Question: Part 1: Write a C program that takes an integer command line argument n , spawns n processes that will each generate a random numbers

Part 1: Write a C program that takes an integer command line argument n, spawns n processes that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each process needs to print out the random number it generates.

Part 2: Write a pthread program that takes an integer command line argument n, spawns n threads that will each generate a random numbers between -100 and 100, and then computes and prints out the sum of these random numbers. Each thread needs to print out the random number it generates.

Detailed requirements:

1. Name the programs in the pattern hw3_2.c and hw3_3.c .

2. The programs should analyze arguments in the command line, in order to determine the number of processes/threads to be created. The format of the command for running a program is as follows (Important! If you don't follow strictly, the script testing your program may not be able to run your program correctly, and you may get lower grades).

./your_program -n number_of_processes_or_threads

3. The programs should print out numbers only, one number on each line. The sum should be printed on the last line. For example, when 10 processes are used, 11 numbers are printed out on 11 lines for each program --- 10 random numbers on the first 10 lines and 1 sum on the last line.

Grading for Each Program:

1. The executable file can be successfully generated with gcc ---- +5 points

2. The program can finish within 1 minute without crash when it is run with the following command: ---- +5 points

./your_program -n 10

3. The processes/threads can be correctly generated. The number of processes/threads matches the command line argument. --- +5 points

4. A correct number of values (random numbers and the sum) are printed out, one on each line. --- +5 points

5. The sum is correctly calculated. ---- +5 points

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!