Skip to content

Process

1. What is a Process State?

A process state represents the current status of a process as it moves through its lifecycle, from creation to completion. This model helps users and the kernel understand how processes grow and execute.

2. Primary (Mandatory) Process States

These are the standard states present in almost all operating systems:

  • New State: The initial state where a process is created (e.g., when you write a program or open an application like Firefox). The process resides in secondary memory (hard disk) at this point.
  • Ready State: Once a process is "popped" or activated, it moves into the Ready Queue in the RAM. It is now active and waiting for its turn to be executed by the CPU.
  • Running State: A process moves here when the CPU starts executing its instructions. In a uniprocessor system, only one process can be in the running state at a time.
  • Terminated State: Once all instructions are executed, the process is finished. Its resources (like RAM addresses) are de-allocated and returned to the system.
  • Wait / Block State: If a process needs to perform an Input/Output (I/O) operation (like reading a file from the disk), it cannot use the CPU. It moves to this state in the RAM to wait for the I/O request to complete, freeing the CPU for other tasks.

3. Secondary (Additional) States

These states are used for efficient memory management, especially when RAM is full:

  • Suspend Wait / Suspend Block: If the Wait Queue in the RAM becomes too full, the Medium-Term Scheduler "swaps out" some waiting processes to secondary memory.
  • Suspend Ready: Similarly, if the Ready Queue is full or a very high-priority (VIP/Kernel) process arrives, some ready processes are moved back to secondary memory temporarily.

4. Types of Schedulers

Schedulers are system software responsible for moving processes between states:

Scheduler Description Responsibility
Long-Term Scheduler Job Scheduler Decides which processes move from New to Ready. It controls the degree of multi-programming.
Short-Term Scheduler CPU Scheduler Decides which process from the Ready Queue gets the CPU (Running state). It is very fast and frequent.
Medium-Term Scheduler Swapper Handles "Swapping." Moves processes between RAM and secondary memory (e.g., to Suspend states) to free up space.

5. Key Concepts in Scheduling

  • Dispatching: The act of the Short-Term Scheduler assigning a process to the CPU.
  • Preemptive Scheduling: The CPU can be taken away from a running process before it finishes (e.g., due to a high-priority process or a time limit/time quantum).
  • Non-Preemptive Scheduling: Once a process gets the CPU, it holds it until it either terminates or moves to a waiting state for I/O.
  • Context Switching: When the CPU switches from one process to another, the system must save the state of the old process and load the saved state for the new process.

6. Practical Tools

  • Windows: Use the Task Manager to see the list of active processes and their statuses.
  • Linux/Unix: Use the ps (Process Status) command to view detailed information about processes, including their IDs and CPU usage.

These lecture notes provide an overview of system calls in an operating system, explaining their necessity, how they function, and their various categories.

1. Introduction to System Calls

A system call is the programmatic way in which a computer program requests a service from the kernel of the operating system it is executed on.

  • User Mode vs. Kernel Mode: Generally, applications and user programs run in user mode. However, to access hardware resources (like a printer, monitor, or hard disk) or specific operating system functionalities, the system must shift to kernel mode.
  • The Bridge: System calls act as the interface or bridge that allows a program to transition from user mode to kernel mode to perform privileged tasks.

2. How System Calls Work

While users often use high-level functions or APIs (like printf() or scanf() in C), these are not the system calls themselves.

  • API/Library Functions: These are higher-level functions that provide a simpler interface for programmers.
  • Execution: When a function like printf() is called, it internally invokes a system call (such as write) to tell the kernel to display text on the monitor. The kernel then carries out the task because the user process does not have the direct privilege to access hardware.

3. Types and Categories of System Calls

Operating systems typically provide hundreds of system calls (e.g., Linux has several hundred, and Windows 7 has around 700). They are categorized as follows:

Used for managing files within the system.

  • Examples: Create, Open, Read, Write, Close, and Delete.
  • Function: These allow a process to manipulate data stored on the hard disk, which is a resource governed by the kernel.

Used for managing hardware devices.

  • Examples: Request device, Release device, Read, Write, and Reposition.
  • Function: Programs use these to interact with hardware like printers, scanners, or monitors. Commands like ioctl (Input/Output Control) are used to manage device attributes.

Used for transferring information between the user program and the operating system.

  • Examples: getpid() (get process ID), getppid() (get parent process ID), time(), and date().
  • Function: These provide metadata about processes or the system itself, such as file permissions, extensions, or system time.

D. Process Control System Calls

Used for managing the lifecycle and execution of processes.

  • Examples: load(), execute(), abort(), fork(), wait(), and signal().
  • Important Call: fork() is used to create a child process from a parent process, enabling multiprocessing and multi-threading environments.

E. Communication System Calls

Used for Inter-Process Communication (IPC), allowing different processes to talk to each other.

  • Examples: pipe(), shmget() (shared memory), and send() / receive() messages.
  • Function: These manage the creation and termination of communication connections between processes.

F. Protection and Security

Used for controlling access to resources and ensuring system security.

  • Examples: chmod() (change permissions), umask(), and managing user privileges.