Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions