Zombie and Orphan Processes in C7 Jan 2025 | 4 min read A process is the execution of an instruction in C programming. When you execute a C program, it turns into a process. During its execution, a process has its own space for memory, resources, and state. It begins, executes its instructions, and then exits. The operating system manages processes by allocating resources like as CPU time, memory, and I/O (input/output) hardware. In this article, you will learn about the zombie and orphan processes in C. Zombie ProcessesA zombie process has completed execution but still has an entry in the process table to report to its parent process. A child process is always turned into a zombie before it has removed from process table. The parent process reads the child process's exit status and removes the child process's entry from the process table. If a parent process failed to run wait() or waitpid() function to gather the termination status of its child processes, such processes might queue up, which could result in a huge number of zombie processes. This buildup of zombie processes can use system resources such as process table entries, although the practical impact is generally low until a large number of zombie processes stay unused. In the following code, the child process completes its execution by using the exit() system call, while the parent sleeps for 40 seconds and thus does not call wait(), and the child process's entry remains in the process table. Example:It is the sample program using the fork() function. Orphan ProcessesAn orphan process is a child process that keeps running even after its parent process has ended or completed its execution. When a parent process dies before the child process processes, children who are orphaned are left behind. Orphaned processes are taken on by the init process (typically with PID 1), which acts as the system's ancestor. The init process accepts orphaned processes and takes over as their new parent. As they have an alternate parent process that will ultimately gather their exit condition when they terminate, orphan processes are prevented from turning into zombie processes. Orphan processes usually continue to run undisturbed by the death of their parent. However, they may run into problems if they were dependent on certain resources or connections to their parent processes that are no longer available. Example:Output: The process of creating the Zombie process.. The parent process with PID: 7941 The parent process waits... Execution of the child process. Parent process is completed. Creation of the Orphan process... The parent process with PID: 7988 The parent process is terminated. Child process executing and then sleeping for a while... Child process completed. The parent process is waits for all child processes If all processes are completed. The parent process is exits Next TopicC Programming Test |
We request you to subscribe our newsletter for upcoming updates.

We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India