Please program in C. Thank you
2. Process Lab Implement a program using Processes The Objective of this lab is for you to implement a program that creates two child processes. A total of 3 processes will exist after the creation (i.e. 1 for the parent process, and 2 child processes). Child Process Both child processes will loop for some random number of iterations, but no more than 30, while the parent process will wait for both to terminate. Open the terminal and use the man pages to lookup the random() function in C (e.g. man random ). You will have to make sure you include the proper #include . Also, in order to use the random number generator you must seed it correctly using srandom() . If the man pages are not enough, use Google! Within the loop, each child should print a message "Child Pid:
is going to sleep!", then call the sleep() function for a random amount of time, but no more than 10 secs (i.e. use the random() ). When the child wakes up, it should print the message "Child Pid: is awake! Where is my Parent: ?". Use the getpid() to obtain the of the current running process, and getppid() to get the of the parent. Use the man pages to lookup getpid() and getppid() . If the man pages are not enough, use Google! Once the loop has terminated the child process should calll exit(0) to terminate. 2. Process Lab Parent Process After forking the two child processes, the parent process must call the wait() function to wait for both child processes to complete. As each processes completes, the parent should print out the message "Child Pid: has completed" using the wait(&status) . Use the man pages to lookup the wait() and its usage. If the man pages are not enough, use Google! Makefile Create the makefile to compile the program. Use the prior labs as examples. You can call your executable anything you want. If those are not enough, use Google! Running your program Bring up another terminal. In the new terminal, lets view the status of the currently running processes by executing the command ps -ef on the command line. ps is the command to show a listing of the process status table. You can get more information about what is ps by viewing the man pages. After typing ps , notice the list of all the processes running in the background such as bash , sshd , init ...etc. These are the programs for the command line shell, terminal, and the parent process of all processes init. There probably are others there that are providing some OS management services as well. Notice in the 2nd and 3rd columns are the PID and parent PPID of each of the processes. In the 4th column is the total time the processes have been running. In your coding terminal start your program you just compiled by typing in its executable name. Return to the other terminal that you executed ps. Lets view the status of all of your processes again after running your program. Notice you now have three processes with the same name as your executable. Look at the PID and PPID and remember their values. Now switch to the terminal running your code. Look at the data being printed out by your program. Notice the pid and ppid values. They should be the same. Terminating your program You can wait for the program to complete, but if you want to terminate the program early, you will need to send the program a signal to terminate. Ctrl-C will bring back the command line, but your program will still be running in the background (i.e. that includes the parent, and two child processes) just like the other OS management services. In order to terminate the program (i.e. process), we need to send a signal using the kill() system call. Look at the process status table and identify the two child processes. They will both have the same process name (i.e. the executable you gave it in your gcc command line in the Makefile), and also have the same number in the process status table for their parent pid PPID . There should also be another process with the executable name that has its PID equal to the PPID of each of the child processes. You must kill the parent process, and the parent will kill the child processes. On the command line type the following. kill -9 \