142k views
1 vote
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.

User Omitobi
by
5.2k points

1 Answer

0 votes

Answer:

#include <stdlib.h>

#include <sys/types.h>

#include <unistd.h>

int main()

{

// Using fork() creates child process which is identical to parent

int pid = fork();

// Creating the Parent process

if (pid > 0)

sleep(10);

// And then the Child process

else

{

exit(0);

}

return 0;

}

Step-by-step explanation:

Using a Text editor enter the code in the Answer section and save it as zombie.c. The created process will be able to run for 10 seconds.

Now open the Terminal and type $ cc zombie.c -o zombie to compile the program which is then saved as an executable file.

With a GNU compiler run the following command ./zombie which will give you an output of the parent process and child process to be used testing.

User Matt Bodily
by
4.7k points