Question: Comments that help in explaining are greatly appreciated, thanks!! If you don't know how to solve it, please allow others to see it, I will
Comments that help in explaining are greatly appreciated, thanks!! If you don't know how to solve it, please allow others to see it, I will definitely give thumbs up if the code runs ;)
Please program this to run on the c language and the Linux operating system (ubuntu)(I use CLion)
Write a program in C that takes a number from the command line and creates as many new processes as specified on the command line. Each process should wait for a random amount of time (between 1 and 10 seconds) before printing a line and exiting (Be careful when using rand() - if you dont seed your random number generator with a rapidly changing value, all your random numbers may start with the same seed).
Sample output on 2 different runs:
luke@abdi23:/test/asn2/1$ ./a.out 11 process 7 is done after sleeping for 0 seconds process 4 is done after sleeping for 0 seconds process 6 is done after sleeping for 1 seconds process 3 is done after sleeping for 2 seconds process 9 is done after sleeping for 4 seconds process 11 is done after sleeping for 5 seconds luke@abdi23:/test/asn2/1$ process 8 is done after sleeping for 5 seconds process 10 is done after sleeping for 7 seconds process 2 is done after sleeping for 8 seconds process 1 is done after sleeping for 8 seconds process 5 is done after sleeping for 9 seconds luke@abdi23:/test/asn2/1$ ./a.out 2 process 2 is done after sleeping for 7 seconds luke@abdi23:/test/asn2/1$ process 1 is done after sleeping for 9 seconds luke@abdi23:/test/asn2/1$
(ignore the command prompt printed in between the screen output)
After this program is done and provided: Re-write the above program replacing all process calls with thread calls using the pthreads library in C. Your program should only exit when all threads have been completed. The program output should be the same (except that there wont be any of those pesky prompts being printed within your program execution).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
