Operating Systems: Processes, Threads, and System Calls
Classified in Computers
Written on in
English with a size of 31.86 KB
Chapter 1: System Fundamentals
Inter-process Communication (IPC):
- Network: Communication between processes over a network.
- Pipe (Special File): Process A writes into a pipe, and Process B reads from it.
Privileged vs. User Mode
The OS runs in privileged mode (also called supervisor or system mode), where specific operations—such as accessing a disk or network card—are permitted. User programs run in user mode and cannot perform these operations directly. When a program requires an OS service, such as accessing a file or creating a process, it is accomplished by a system call.
CPU Instruction Cycle
The CPU executes programs through a continuous loop:
- Fetch Instruction
- Decode and Execute
- Read/Write Data
- Loop until powered off
OS Invocation Methods
- System Call: A process requests a system service (e.g., exit). It functions like a procedure call but occurs "outside" the process.
- Interrupt: An external asynchronous event triggers a context switch (e.g., Timer, I/O device). This is independent of the user process.
- Trap or Exception: An internal synchronous event within a process triggers a context switch (e.g., protection violation, segmentation fault, or division by zero).
Chapter 2: Processes and Threads
Understanding Processes
A process is a program in execution—an active entity with a program counter specifying the next instruction and a set of associated resources.
Process Creation
Processes are created in two primary ways:
- System Initialization: One or more processes are created when the OS starts.
- System Call: An explicit request for a new process, originating from:
- User requests (e.g., from a shell).
- Already running processes (User programs or System daemons).
Process Lifecycle
Creation Steps:
- Load code and data into memory.
- Create an empty call stack.
- Initialize state.
- Make the process ready to run.
Cloning a Process:
- Save the state of the current process.
- Make a copy of the current code, data, stack, and OS state.
- Make the process ready to run.
Advantages of Threads
Threads allow a single application to perform multiple tasks simultaneously, are faster to create or destroy, and enable the overlapping of computation and I/O.
- Responsiveness: Programs continue running even if part of the application is blocked or performing lengthy operations.
- Resource Sharing: Unlike processes, which require explicit shared memory or message passing, threads share the memory and resources of their parent process by default.
- Economy: Creating and context-switching threads is more efficient in terms of time and memory.
- Scalability: Threads can run in parallel on different processing cores.