Question: Using Ubuntu Process Suspension and Termination This section introduces the wait() system call and the exit() function, which are usually related as in parent and

Using Ubuntu Process Suspension and Termination

This section introduces the wait() system call and the exit() function, which are usually related as in parent and child. Note that there are several different versions of wait() (e.g. some specify who to wait for). The exit() function causes program termination; resources are recovered, files are closed, resource usage statistics are recorded, and the parent is notified via a signal (provided it has executed a wait). Refer to the man pages to learn the syntax for using these functions.

Sample Program

#include #include #include #include #include

int main() {

// use these variables

pid_t pid, child; int status;

if ((pid = fork()) < 0) { perror("fork failure"); exit(1); } else if (pid == 0) { printf("I am child PID %ld ", (long) getpid()); /* insert an appropriate form of the exit() function here */

} else { /* insert an appropriate form of the wait() system call here */

printf("Child PID %ld terminated with return status %d ", (long) child, status); } return 0; }

Perform the following operations and answer the questions:

  • add function calls to Sample Program so that it correctly uses wait() and exit(). Basically, implement the comments, making use of the pre-declared variables referenced in the printf() statement.

1. provide the exact line of code that you inserted for the wait() system call.

2. who prints first, the child or the parent? Why?

3. what two values are printed out by the parent in Sample Program 3? (No, not the actual numbers, but what they mean.) In other words, describe the interaction between the exit() function and the wait() system call. You may want to experiment by changing the value to better understand the interaction.

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!