Question: Given the following code for Program 1 (that forks a child process that becomes a zombie process), create a new program that does #1 automatically

Given the following code for Program 1 (that forks a child process that becomes a zombie process), create a new program that does #1 automatically so you do not have to enter the commands ps and kill manually. Your program has to: (a) create zombie processes by running your C program of #1, (b) Obtain the state of each process and find if there is any process that is zombie, (c) Show a list of processes with their states, (d) kill the parent of any process that is zombie, and (e) show the updated list of processes with their states.

Please comment or explain the program 2 code.

Program 1 code:

#include #include #include int main() { // Fork returns process id in parent process int pid = fork(); if(pid<0){ //exit(1); printf("failed to fork "); return -1; } // Parent process if (pid > 0){ printf("parent pid: %d ", getpid()); sleep(10); } // Child process else{ printf("child pid: %d ", getpid()); exit(0); } return 0; }

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!