Question: Zombie process A zombie process in system programming refers to a process that has completed execution but still has an entry in the process table.

Zombie process
A zombie process in system programming refers to a process that has completed execution but still has an entry in the process table.
This happens when the parent process hasn't yet read the exit status of the child process (via wait() or waitpid() system calls). Here
are the key points about zombie processes:
State: The process is in a "terminated" state but is not fully removed from the system as its parent process hasn't called wait() to
collect its exit status. This state is called Z (zombie) in Unix/Linux systems.
Parent Process Role:
The parent process is responsible for calling wait() or waitpid() to retrieve the termination status of its child.
If the parent process doesnt call these functions, the child remains in the zombie state.
If you run the ps command before the parent gets terminated the output of ps will show the entry of a zombie process(denoted by
defunct ). This happens because the child is no longer active but its exit code needs to be stored in case the parent subsequently calls
wait.
2
Zombie Process
//zombie.c
#include
#include
int main()
{
pid_t t;
t=fork();
if(t==0)
{
printf("Child having id %d
",getpid());
}
else
{
printf("Parent having id %d
",getpid());
sleep(15); // Parent sleeps. Run the ps command during this time
}
}
3
Lab exercise
Q1. Create a scenario where a parent has two child process C1 and C2
such that C1 becomes a zombie while C2 becomes an orphan process.
give me the code for this question.
follow the above concept. and give me the clear code and output , explanation.

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 Programming Questions!