Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment: Write a simple program that uses the fork function. The new process created by fork is called the child process. The function is called
Assignment: Write a simple program that uses the "fork" function. The new process created by fork is called the "child" process. The function is called once but returns twice. Both the child and the parent continue executing with the instruction that follows the call to fork. Here is a typical example: / parent creates a process / pid = fork () ; / the return value is a process ID, that ALWAYS needs to be tested / switch (pid) \{ case -1: / error: fork was unsuccessful / break; case : / this is the child process / / no process ID / / do something ... / break; default: / this is the parent process / / pid=process ID of the child / // 3 / both processes continue here / You can list processes by using the ps command or the top command (to see the manual pages use "man ps" or "man top"). Under Unix/Linux a process that has terminated, but whose parent has not yet waited for it is called a zombie. Adjust the sleep calls for parent and child and use the command p to answer these questions (add them as comments at the end of your program): 1. What status is being printed when the child terminates before the parent (in another terminal use: ps ajxf | grep yourProgramName)? Note: run the command "man ps" for more options. 2. What is the parent process ID (PPID) of a child process whose parent terminates before the child
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