Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Process vs Parent Process vs Child Process
In Operating System, the fork() system call is used by a process to create another process. The process that uses the fork() system call is the parent process and the process consequently created is known as the child process.
Process
A process is an active program ? a program that is under execution. It is more than just the program code as it includes the program counter, process stack, registers, program code, and other runtime information. The program code itself is only the text section of a process.
A process changes its state as it executes, depending on the current activity. The different states that a process goes through during its execution are new, ready, running, blocked, and terminated.
Each process has an associated Process Control Block (PCB) that contains important information such as process state, process ID (PID), program counter, CPU registers, memory management information, and I/O status information.
Parent Process
All processes in an operating system are created when an existing process executes the fork() system call, except for the initial startup process. The process that uses the fork() system call is the parent process. A parent process may have multiple child processes, but each child process has only one parent process.
When fork() is called successfully:
The PID of the child process is returned to the parent process
0 is returned to the child process
On failure, -1 is returned to the parent process and no child is created
Child Process
A child process is a process created by a parent process using the fork() system call. It may also be called a subprocess or subtask. The child process is created as a copy of its parent process and inherits most of its attributes, including:
Process image (code, data, heap, stack)
Environment variables
Open file descriptors
Signal handling settings
If a child process has no parent process, it was created directly by the kernel. When a child process exits or is interrupted, a SIGCHLD signal is sent to the parent process.
Process Hierarchy Example
Key Differences
| Aspect | Parent Process | Child Process |
|---|---|---|
| Creation | Calls fork() system call | Created by fork() system call |
| Return Value | Receives child's PID | Receives 0 |
| Relationship | Can have multiple children | Has exactly one parent |
| Termination | Receives SIGCHLD signal | Sends SIGCHLD on exit |
Conclusion
Understanding the relationship between processes, parent processes, and child processes is fundamental to operating systems. The fork() system call creates a hierarchical process structure where parent processes can create multiple children, each inheriting the parent's attributes while having its own unique process ID and execution context.
