Quick links
Latest articles
Internship
Members
New...
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

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






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



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 (2015-2018), Some rights reserved.