Parent Process vs. Child Process including PID & PPID


Parent Process

All the processes in an operating system are created when a process executes the fork () system call except the startup process. The process that used the fork () system call is the parent process. In other words, a parent process is one that creates a child's process. A parent process may have multiple child processes but a child process only one parent process.

On the success of a fork () system call, the PID of the child process is returned to the parent process and 0 is returned to the child process. On the failure of a fork () system call, -1 is returned to the parent process and a child process is not created.


Child Process

A child process is a process created by a parent process in an operating system using a fork () system call. A child process may also be called a sub-processor a subtask.

A child process is created as its parent process’s copy and inherits most of its attributes. If a child process has no parent process, it was created directly by the kernel.

If a child's process exits or is interrupted, then a SIGCHLD signal is sent to the parent process.


Some differences between the child and parent process are:

They have different pids

In the parent, fork( ) returns the pid of the child process if a child process is created

In the child, fork( ) always returns 0

Separate copies of all data, including variables with their current values and the stack

Separate program counter (PC) indicating where to execute next; originally both have the same value but they are thereafter separate

After fork, the two processes do not share variables


PID & PPID

In Linux, an executable stored on a disk is called a program, and a program loaded into memory and running is called a process. When a process is started, it is given a unique number called process ID (PID) that identifies that process to the system. If you ever need to kill a process, for example, you can refer to it by its PID.

In addition to a unique process ID, each process is assigned a parent process ID (PPID) that tells which process started it. The PPID is the PID of the process’s parent.

For example, if process1 with a PID of 101 starts a process named process2, then process2 will be given a unique PID, such as 3240, but it will be given the PPID of 101. It’s a parent-child relationship. A single parent process may spawn several child processes, each with a unique PID but all sharing the same PPID

When we execute a program on your Unix system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.

Whenever you issue a command in Unix, it creates, or starts, a new process. When you tried out the ls command to list the directory contents, you started a process. A process, in simple terms, is an instance of a running program.

The operating system tracks processes through a five-digit ID number known as the pid or the process ID. Each process in the system has a unique pid.

Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process.

Next Post Previous Post
No Comment
Add Comment
comment url