$RHIYKNM
$RHIYKNM
a) Process States
Each process in Linux goes through different states:
1. Running – The process is currently executing instructions.
2. Ready – The process is ready to run but waiting for CPU allocation.
3. Blocked (Waiting) – The process is waiting for I/O or other resources.
• Process ID (PID)
• Parent Process ID (PPID)
• Process state
• CPU registers
• Program counter
• Memory management info
• Scheduling parameters
This structure helps the OS manage and schedule the processes efficiently.
c) Process Hierarchy
Processes in Linux are organized in a hierarchical structure, where each process is created by
a parent using the fork() system call. The root process is usually init or systemd, having PID 1.
• Use the command pstree to view the process tree.
• fork() – Creates a new process.
• exec() – Replaces the current process image with a new one.
• wait() – Parent waits for the child process to complete.
e) Process Identifiers
Every process has a unique Process ID (PID). Linux also assigns:
• PGID – Process Group ID
• SID – Session ID
Scheduling in Linux
Scheduling is the strategy used by the kernel to decide which process runs next. The
scheduler ensures CPU time is shared among all processes fairly and efficiently.
a) Types of Scheduling
1. Preemptive Scheduling
o Processes can be interrupted in the middle of execution.
o Ensures responsiveness, especially in real-time applications.
2. Non-Preemptive Scheduling
o Once a process gets the CPU, it holds it until it finishes or blocks.
o Not used in modern Linux due to poor responsiveness.
Key Features:
• Maintains a red-black tree of runnable processes.
• Each process gets a virtual runtime (vruntime) representing how much CPU time it
has received.
• The process with the smallest vruntime is selected next.
• Ensures fair distribution of CPU among all processes.
Working:
• Uses time slices based on process weight (priority).
• Higher-priority processes get more CPU time.
• Ensures fairness over long term, not immediate response.
d) Real-Time Scheduling
For time-critical applications, Linux provides:
• SCHED_FIFO – Static priority; runs until blocked or preempted.
• SCHED_RR – Like FIFO, but each process gets a fixed time slice.
• SCHED_DEADLINE – Tasks specify runtime, deadline, and period.
These are used in industrial control systems, embedded systems, etc.
Linux supports multitasking, where multiple processes are run simultaneously. Each of
these processes needs memory to function. The kernel ensures:
• Process Isolation: Each process gets its own private address space, enhancing
security and stability.
• Efficient RAM Usage: Allows only the necessary parts of a program to be loaded into
RAM.
• Swapping and Overcommit: Processes can use more memory than physically
available by using disk-based swap.
Address Space Layout (for a process):
• Text Segment: Stores executable code.
• Data Segment: Stores initialized global/static variables.
• BSS Segment: Stores uninitialized data.
• Heap: Grows upwards as memory is dynamically allocated.
• Stack: Grows downwards for function calls and local variables.
Zone Description
Swapping:
When RAM is insufficient, Linux moves inactive pages to a special disk area
called swap space.
• Swap File/Partition: Acts as an extension of RAM.
• Swapping Process: The kernel identifies least-used memory pages and
writes them to swap.