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

w8sCxppQRjzZQAAAABJRU5ErkJggg==

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:

  1. Fetch Instruction
  2. Decode and Execute
  3. Read/Write Data
  4. 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:

  1. System Initialization: One or more processes are created when the OS starts.
  2. 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:

  1. Load code and data into memory.
  2. Create an empty call stack.
  3. Initialize state.
  4. Make the process ready to run.

Cloning a Process:

  1. Save the state of the current process.
  2. Make a copy of the current code, data, stack, and OS state.
  3. 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.

Related entries: