Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using either a UNIX or a Linux system, write a C program that forks a child proc

ID: 3785954 • Letter: U

Question

Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command ps -l The process states are shown below the S column; processes with a state of Z are zombies. The process identifier (pid) of the child process is listed in the PID column, and that of the parent is listed in the PPID column. Perhaps the easiest way to determine that the child process is indeed a zombie is to run the program that you have written in the background (using the &) and then run the command ps -l to determine whether the child is a zombie process. Because you do not want too many zombie processes existing in the system, you will need to remove the one that you have created. The easiest way to do that is to terminate the parent process using the kill command. For example, if the process id of the parent is 4884, you would enter kill -9 4884
Upload a video of the program running and you demonstrating the operations. Include a zip of the project as well.

I need this problem solved, a video and zip of the project.

Explanation / Answer

#include <stdio.h>

int main()
{
int pid;
//create child process
pid = fork();
//if pid greater than 0 it's parent process
if(pid > 0)
{
printf("Parent process with pid %d has created child process with pid %d and exiting ",getpid(),pid);
}
else
{
//
printf("Child process with pid %d sleeping",getpid());
sleep(10);
}
return 0;
}

--------------------------------------------------------------------------------------------------------

//output

main&                                                                                                                                                                   

[1] 153                                                                                                                                                                         

sh-4.2$ Parent process with pid 153 has created child process with pid 154 and exiting   

[1]+  Done                    main

F S   UID    PID   PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD                                                                                                         

0 S 42804    141      1  0  80   0 -  2944 wait   pts/6    00:00:00 sh                                                                                                          

1 Z 42804    154      1  0  80   0 -     0 exit   pts/6    00:00:00 main <defunct>                                                                                              

0 R 42804    156    141  0  80   0 - 11326 -      pts/6    00:00:00 ps

Child process with pid 154 has become zombies , you can see the status of the process under S ,it's Z

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote