Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions