CSC 374: Computer Systems II: 2022 Fall, Assignment #2Last Modified 2022 October 10Purpose:To practice creating processes and signal handling.ComputingPlease ssh into one of the...

1 answer below »
.


CSC 374: Computer Systems II: 2022 Fall, Assignment #2 Last Modified 2022 October 10 Purpose: To practice creating processes and signal handling. Computing Please ssh into one of the following: · cdmlsrvprd01.dpu.depaul.edu or use your own Un*x machine (e.g. Linux or MacOS) Overview: We will write a program that "recursively" calls itself 2 times called selfCaller. Thus, there will be three processes running the same program. In one window I run the program: $ ./selfCaller In a second window I monitor the processes: $ ps aux| grep selfCaller ps aux |grep selfCaller instruc+ 8009 0.0 0.0 4220 352 pts/3 S+ 09:51 0:00 ./selfCaller instruc+ 8010 0.0 0.0 4220 352 pts/3 S+ 09:51 0:00 selfCaller 1 instruc+ 8011 0.0 0.0 4220 352 pts/3 S+ 09:51 0:00 selfCaller 0 instruc+ 8069 0.0 0.0 112712 968 pts/0 S+ 09:52 0:00 grep --color=auto selfCaller · Process number 8009 is the one I directly created by running ./selfCaller. · Processes 8010 was created by 8009. · Process 8011 was created by 8010. · Process 8069 is not running selfCaller. Instead, it is the grep selfCaller process that is looking for the selfCaller processes. All selfCaller processes have a level value, which is an integer telling how many more "recursive" calls to do. · For 8009 it is 2, the default value. · For 8010 it is 1 (the value on the command line) · For 8011 it is 0 (the value on the command line) All processes receive signals from themselves and (if they have one) their child. Also, all process count the number of signals they receive. Received signal: Action: SIGALRM (Every process sends SIGALRM to itself.) · Do printf("Process %d: called level 0\n",level); · Tell the OS to send another SIGALRM to yourself rand() % 10 + 1 seconds in the future · Increment numTimesCalled[0] · If level is not 2 then send SIGUSR1 to its parent. SIGUSR1 · Do printf("Process %d: called level 1\n",level); · Increment numTimesCalled[1] · If level is not 2 then send SIGUSR2 to its parent. SIGUSR2 · Do printf("Process %d: called level 2\n",level); · Increment numTimesCalled[2] SIGINT Have the program stop running by setting global var shouldRun to 0. Assignment: 1. Copy and paste the following file: 2. /*-------------------------------------------------------------------------* 3. *--- ---* 4. *--- selfCaller.c ---* 5. *--- ---* 6. *--- This program demonstrates process programming and ---* 7. *--- signalling by "recursively" calling itself a limited number of ---* 8. *--- and selectively signally its parent process. ---* 9. *--- ---* 10. *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* 11. *--- ---* 12. *--- Version 1a Joseph Phillips ---* 13. *--- ---* 14. *-------------------------------------------------------------------------*/ 15. 16. #include 17. #include 18. #include 19. #include 20. #include 21. 22. const intTEXT_LEN= 16; 23. 24. const intNUM_SECS_TO_RUN= 30; 25. 26. #definePROGNAME"selfCaller" 27. 28. intnumTimesCalled[3] 29. = {0,0,0}; 30. 31. pid_tpidToSignal= -1; 32. 33. pid_tchildPid= -1; 34. 35. intlevel= +2; 36. 37. intshouldRun= 1; 38. 39. // YOUR SIGNAL HANDLERS HERE 40. 41. 42. intmain(intargc, 43. char*argv[] 44. ) 45. { 46. srand(getpid()); 47. 48. // YOUR CODE HERE 49. 50. 51. 52. 53. 54. printf("Level %d: %d %d %d\n",level, 55. numTimesCalled[0],numTimesCalled[1],numTimesCalled[2] 56. ); 57. 58. return(EXIT_SUCCESS); } 59. Write the signal handlers A description of what they do is given in the table above the code. 60. Finish main() a. It should check the command line arguments. If there is a command line argument then it should set level to the integer value of that string. If there is no command line argument, or the given command line argument is neither 0 nor 1, then set level to 2. b. If level is greater than 0 then it should create a new child to "recursively" call PROGNAME. The child process should give itself the command line argument value of level-1 as a string. One way to do that is with: c. chartext[TEXT_LEN]; d. snprintf(text,TEXT_LEN,"%d",level-1); Now text contains the integer level-1 as a string. If the program named PROGNAME cannot be run then the child process should do: fprintf(stderr,"Cannot find %s\n",PROGNAME); exit(EXIT_FAILURE); e. Install your signal handlers for SIGALRM, SIGUSR1, SIGUSR2 and SIGINT. f. Tell the OS to send SIGALRM to this process rand() % 10 + 1 seconds in the future. g. Do this: h. if (level == 2) i. { j. inti; k. l. for (i = 0; i < num_secs_to_run; i++) m. { n. sleep(1); o. } p. } q. else r. { s. pidtosignal= getppid(); t. u. while (shouldrun) v. { w. sleep(1); x. } } what that means is: · if you are the original parent (level == 2) then hang out for 30 seconds. · otherwise, note who your parent is, and keep running until told to quit. y. only if this process has a child process then send sigint to that process and wait() for it to finish. z. print the signal counts, and return exit_success to the os (already done). how to make the program: $ gcc selfcaller -o selfcaller in one window call it: $ ./selfcaller in another window moniter it: $ ps aux| grep selfcaller very important! during debugging, you may have rogue processes. you must kill them with $ kill -9 processidnumber because if you make too many the os will not let you make any more, and not even let you login! sample output: $ ./selfcaller process 2: called level 0 process 2: called level 0 process 1: called level 0 process 2: called level 1 process 0: called level 0 process 1: called level 1 process 2: called level 2 process 1: called level 0 process 2: called level 1 process 0: called level 0 process 1: called level 1 process 2: called level 2 process 1: called level 0 process 2: called level 1 process 2: called level 0 process 2: called level 0 process 0: called level 0 process 1: called level 1 process 2: called level 2 process 1: called level 0 process 2: called level 1 process 2: called level 0 level 0: 3 0 0 level 1: 4 3 0 level 2: 5 4 3 this means that: · level 0 sent sigalrm to itself and sigusr1 to its parent 3 times. · level 1 received sigusr1 and sent sigusr2 to its parent 3 times. · level 2 received sigusr2 3 times. · level 1 sent sigalrm to itself and sigusr1 to its parent 4 times. · level 2 received sigusr1 4 times. · level 2 sent sigalrm to itself 5 times. num_secs_to_run;="" i++)="" m.="" {="" n.="" sleep(1);="" o.="" }="" p.="" }="" q.="" else="" r.="" {="" s.="" pidtosignal="getppid();" t.="" u.="" while="" (shouldrun)="" v.="" {="" w.="" sleep(1);="" x.="" }="" }="" what="" that="" means="" is:="" ·="" if="" you="" are="" the="" original="" parent="" (level="=" 2)="" then="" hang="" out="" for="" 30="" seconds.="" ·="" otherwise,="" note="" who="" your="" parent="" is,="" and="" keep="" running="" until="" told="" to="" quit.="" y.="" only="" if="" this="" process="" has="" a="" child="" process then="" send sigint to="" that="" process="" and wait() for="" it="" to="" finish.="" z.="" print="" the="" signal="" counts,="" and="" return exit_success to="" the="" os="" (already="" done).="" how="" to="" make="" the="" program:="" $="" gcc="" selfcaller="" -o="" selfcaller="" in="" one="" window="" call="" it:="" $="" ./selfcaller="" in="" another="" window="" moniter="" it:="" $="" ps="" aux|="" grep="" selfcaller="" very="" important! during="" debugging,="" you="" may="" have="" rogue="" processes. you="" must kill="" them="" with="" $="" kill="" -9="" processidnumber="" because="" if="" you="" make="" too="" many="" the="" os="" will not let="" you="" make="" any="" more,="" and not even="" let="" you="" login!="" sample="" output:="" $="" ./selfcaller="" process="" 2:="" called="" level="" 0="" process="" 2:="" called="" level="" 0="" process="" 1:="" called="" level="" 0="" process="" 2:="" called="" level="" 1="" process="" 0:="" called="" level="" 0="" process="" 1:="" called="" level="" 1="" process="" 2:="" called="" level="" 2="" process="" 1:="" called="" level="" 0="" process="" 2:="" called="" level="" 1="" process="" 0:="" called="" level="" 0="" process="" 1:="" called="" level="" 1="" process="" 2:="" called="" level="" 2="" process="" 1:="" called="" level="" 0="" process="" 2:="" called="" level="" 1="" process="" 2:="" called="" level="" 0="" process="" 2:="" called="" level="" 0="" process="" 0:="" called="" level="" 0="" process="" 1:="" called="" level="" 1="" process="" 2:="" called="" level="" 2="" process="" 1:="" called="" level="" 0="" process="" 2:="" called="" level="" 1="" process="" 2:="" called="" level="" 0="" level="" 0:="" 3="" 0="" 0="" level="" 1:="" 4="" 3="" 0="" level="" 2:="" 5="" 4="" 3="" this="" means="" that:="" ·="" level="" 0="" sent sigalrm to="" itself="" and sigusr1 to="" its="" parent="" 3="" times.="" ·="" level="" 1="" received sigusr1 and="" sent sigusr2 to="" its="" parent="" 3="" times.="" ·="" level="" 2="" received sigusr2 3="" times.="" ·="" level="" 1="" sent sigalrm to="" itself="" and sigusr1 to="" its="" parent="" 4="" times.="" ·="" level="" 2="" received sigusr1 4="" times.="" ·="" level="" 2="" sent sigalrm to="" itself="" 5="">
Answered Same DayOct 17, 2022

Answer To: CSC 374: Computer Systems II: 2022 Fall, Assignment #2Last Modified 2022 October 10Purpose:To...

Nidhi answered on Oct 18 2022
46 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here