How does the OS manage Processes ?
Linux manages processes using a multitasking and multiuser model. Here's a brief overview of how it handles processes:
Process Creation and Termination:
Linux creates processes using the fork() system call, which duplicates an existing process. The child process inherits most attributes of the parent.
Processes can be terminated either voluntarily using the exit() system call or forcibly with signals (e.g., SIGTERM or SIGKILL).
Linux employs a scheduler to determine which process gets CPU time. It uses scheduling algorithms like the Completely Fair Scheduler (CFS) to allocate CPU resources fairly.
The scheduler can preempt running processes and select new ones to run based on priority and other factors.
Processes in Linux can be in various states, including Running, Ready, and Blocked (or Sleeping), depending on whether they are actively executing, waiting for CPU time, or waiting for events like I/O operations.
When the scheduler switches between processes, a context switch occurs. It involves saving the state of the currently running process and loading the state of the next process to execute.
Process Control Block (PCB):
Linux maintains a Process Control Block (PCB) for each process. The PCB stores information about the process, including its state, program counter, and resource usage.
Inter-Process Communication (IPC):
Linux provides various IPC mechanisms, such as pipes, sockets, shared memory, and signals, for processes to communicate and synchronize their activities.
Linux processes often have parent-child relationships. Child processes can inherit file handles and other attributes from their parent.