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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started