
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Maximum number of Zombie processes a system can handle in C++
Given the task is to find the maximum number of Zombie processes that a system can handle or in other words, the program does not stop its execution.
A Zombie process (also known as defunct process) is a process that has completed its process via exit() (system call) but still has an entry in the process table.
Approach used in the below program as follows
Note that <unistd.h>should be added in order to run the program.
In main() function initialize num = 0 of type int which we will iterate until the program stops being executed.
To initiate a zombie process create a while statement with the condition − while( fork() > 0 )
Fork() system call is used for initiating a new process known as the child process which run concurrently and make the fork() call (which is the parent process).
Inside the while loop increment num as well as print it.
Example
#include<iostream> #include<unistd.h> using namespace std; int main(){ int num = 0; while (fork() > 0){ num++; cout<<num<<" "; } }
Output
If we run the above code we will get the following output −
In the above output num stops incrementing at 93. But this number is not fixed and can vary depending upon the system configuration.
- Related Articles
- Zombie and Orphan Processes in Linux
- Zombie vs Orphan vs Daemon Processes
- How to Find the List of Daemon Processes and Zombie Processes in Linux
- Find maximum number that can be formed using digits of a given number in C++
- In MySQL, how can we convert a value from one number system to the value in another number system?
- Maximum Number of Events That Can Be Attended in C++
- Maximum number of candies that can be bought in C
- Maximum number of threads that can be created within a process in C
- Maximum number of squares that can fit in a right angle isosceles triangle in C++
- Program to find maximum number of coins we can collect in Python
- Maximum number of segments that can contain the given points in C++
- What are Zombie Computer?
- How to Clean a Linux Zombie Process
- What is Zombie Process in Linux?
- How can kernels context-switch between processes?
