Home » C programs

C program to demonstrate zombie process



C program for zombie process: In this post, we are going to implement program for zombie process.
Submitted by Hritik Raj, on July 26, 2018

Zombie process

A process which has finished its execution but still has an entry in the process table to report to its parent process is known as a zombie process.

In the following code, you can see that the parent will sleep for 20 sec, so it will complete its execution after 20 sec. But, Child will finish its execution using exit() system call while its parent process has gone for sleep.

After execution the child must report to its parent, So the child process entry has to be in the process table to report to its parent even after it has finished execution.

Note: fork() is a UNIX system call so following program will work only on UNIX based operating systems.

The following code will not produce any output. It is just for demonstration purpose.

Program for zombie process in C



#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
	// fork() creates child process identical to parent
	int pid = fork();

	// if pid is greater than 0 than it is parent process
	// if pid is 0 then it is child process
	// if pid is -ve , it means fork() failed to create child process

	// Parent process
	if (pid > 0)
		sleep(20);

	// Child process
	else
	{
		exit(0);
	}
	
	return 0;

}

Reference: Zombie and Orphan Processes in C






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Quick links
Latest articles, Internship, Members
New...
Coding problems, Algorithms, Discrete Mathematics, Big data
Languages
C, C++, C++ STL, Java, Data Structure, C#.Net, Android, Kotlin, SQL
Web
PHP, Python, JavaScript, CSS, Ajax, Node.js, Web prog.
Programs
C, C++, DS, Java, C#, Python
Aptitude
C, C++, Java, DBMS
Interview
C, Embedded C, Java, SEO, HR
CS Subjects
CS Basics O.S. Networks DBMS Embedded Systems Cloud Computing Machine learning CS Organizations Linux DOS
More...
Articles, Puzzles, News/Updates


Recommended posts
C Tips & Tricks, C++ Tips & Tricks
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distros of 2018
C programming optimization techniques
Differences b/w C & Embedded C?
Embedded C Interview Q. & A.
C programming tips for Embedded Development
Basic rules of writing a C program
Important points (rules) to remember while writing C/C++ program
Top 5 Websites for solving programming challenges
Read more...


Others...
Computer G.K. (MCQ)
Most viewed pages...
Categories...



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.