Question: Use the following algorithm and specific instructions to develop a short, simple C program called to create an orphan process. a. Add the include directives

Use the following algorithm and specific instructions to develop a short, simple C program called to create an orphan process.

a. Add the include directives for the stdio.h, stdlib.h and unistd.h libraries. b. Declare a pointer to a char called name. c. Declare a variable called pid with the data type pid_t and invoke the fork() system call, assigning the result to pid. d. Write an if-else if-else branching statement to handle the child process, parent process, and error case, respectively.

i. In the child process, print "child: %d started " using the getpid() system call for the %d. Then, print "child: parent = %d " using the getppid() system call for the %d. Now, print another child status (use "child: ") to indicate the child is about to go to sleep. Then, sleep for 25 seconds. Finally, print a child status to indicate that the child just woke up.

ii. In the parent process, print "parent: %d started " using the getpid() system call for the %d. Then print "parent: parent = %d " using the getppid() system call for the %d.

iii. In the error case, call the perror() system call with "fork error".

e. Outside of the if-else if-else branching statement, use the ternary operator to assign "child" to the name character pointer if pid is 0 and "parent" otherwise. Then, print "%s: terminating " using the name character pointer for the %s.

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!