Menu
support@authoritypapers.com
+1(805) 568 7317

threads the system 3 function this program requires careful use of pointers to diff 5192439

: Threads & the system(3) function: This program requires careful use of pointers to different types (void *, char *, long *, …) and conversions between them. The program should take as a command line argument the number of threads to create (from 1 to 10); the thread IDs of each thread created must be stored in an array of thread IDs (for the join function; see below). Each thread created will execute the same runnable function (this means there is one runnable function, not ten!). The runnable function will be passed an argument by means of a void *, the arguments varying from 1 to 10. This argument (minus 1) will be used in the thread to invoke the system(3) function passing it a shell command to execute; this argument (without the minus 1) will also be used by the runnable function as its exit status when pthread_exit is called. Here is a partial example of a runnable function called thread_func: void *thread_func(void *arg) { pid_t pid; pthread_t tid; char cmds[10][15] = {“echo What0”, “echo a0”, “echo beautiful0”, “echo day0”, “echo for0”, “echo a0”, “echo walk0”, “echo in0”, “echo the0”, “echo park.0” }; pid = getpid(); tid = pthread_self(); . . . pthread_exit(arg); } After the main program creates 1 to 10 threads it will await their exit using pthread_join and will print out the exit status of each thread created above. There is an error in the example in the text: when printing out the exit status returned by pthread_join make sure to only use the least significant 7 bits (i.e., mask off the bits with: & 0x7f), and you will probably need to convert the void *, tret, to a long *: lret = (long *)tret; fprintf(stdout, “Main: thread %d returned %ldn”, i+1, (*lret & 0x7f)); Below is a sample of the output expected. Your output should contain the same information, but note that scheduling differences will result in runs that have different orders: rcm$ ass08 10 Main: thread 1 created Thread 1, pid 40849, tid 4372123648 Main: thread 2 created Thread 2, pid 40849, tid 4372660224 Main: thread 3 created Thread 3, pid 40849, tid 4373196800 Main: thread 4 created Main: thread 5 created Main: thread 6 created Main: thread 7 created Main: thread 8 created Main: thread 9 created Main: thread 10 created Thread 4, pid 40849, tid 4373733376 Thread 5, pid 40849, tid 4374269952 Thread 6, pid 40849, tid 4374806528 Thread 7, pid 40849, tid 4375343104 Thread 8, pid 40849, tid 4375879680 Thread 9, pid 40849, tid 4376416256 Thread 10, pid 40849, tid 4376952832 What Main: thread 1 returned 1 a Main: thread 2 returned 2 beautiful Main: thread 3 returned 3 day Main: thread 4 returned 4 for Main: thread 5 returned 5 a Main: thread 6 returned 6 walk Main: thread 7 returned 7 in Main: thread 8 returned 8 the Main: thread 9 returned 9 park. Main: thread 10 returned 10

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now