CS330 - Operating Systems
Process Concept, Scheduling, IPC, and Management
A process is a program in execution. It is the unit of work in most systems. A process is more than just program code (text section); it includes current activity represented by program counter and processor registers.
| Program | Process |
|---|---|
| Passive entity stored on disk | Active entity with program counter |
| Executable file (code) | Program loaded into memory |
| Static | Dynamic, has state |
| One program | Can have multiple processes |
A process includes:
Text and data sections have fixed size, while heap and stack can grow dynamically. Stack and heap grow toward each other but must not overlap!
As a process executes, it changes state. A process may be in one of the following states:
| State | Description |
|---|---|
| New | The process is being created |
| Ready | The process is waiting to be assigned to a processor |
| Running | Instructions are being executed |
| Waiting | The process is waiting for some event to occur (I/O completion or signal) |
| Terminated | The process has finished execution |
Q: A process that is currently in the 'Running' state can next go to which states?
Answer: A running process can go to:
Each process is represented in the OS by a Process Control Block (PCB), also called a Task Control Block (TCB). The PCB contains all information associated with a specific process.
| Field | Contains |
|---|---|
| Process State | New, ready, running, waiting, terminated |
| Program Counter | Address of next instruction to execute |
| CPU Registers | Contents of all process-centric registers |
| CPU Scheduling Info | Priority, scheduling queue pointers |
| Memory Management | Page tables, memory limits, segment tables |
| Accounting Info | CPU used, clock time elapsed, time limits |
| I/O Status | List of I/O devices allocated, open files |
The process scheduler selects among available processes for next execution on CPU core. The goal is to maximize CPU utilization and quickly switch processes onto CPU.
Processes migrate among the various queues during their lifetime.
| Scheduler Type | Function | Frequency |
|---|---|---|
| Long-term | Selects processes from job pool to load into memory | Infrequent (seconds, minutes) |
| Short-term | Selects from ready queue to execute on CPU | Very frequent (milliseconds) |
| Medium-term | Swapping - removes process from memory temporarily | As needed |
Shows flow between ready queue, CPU, and I/O queues
When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process via a context switch.
Q: Describe the actions taken by a kernel to context-switch between processes.
Answer:
A process may create several new processes. The creating process is the parent, and new processes are children, forming a tree of processes.
Q: What will be the output at lines A, B, C, and D? (Assume parent PID=2600, child PID=2603)
Answer:
A process terminates when it finishes executing its final statement and calls exit()
system call.
Processes may be independent or cooperating. Cooperating processes need IPC mechanisms to exchange data and information.
Several users may need same information
Break task into subtasks running in parallel
Divide system functions into separate processes
User may work on many tasks simultaneously
| Aspect | Options |
|---|---|
| Naming |
• Direct: send(P, message), receive(Q, message) • Indirect: via mailboxes/ports |
| Synchronization |
• Blocking (synchronous) • Non-blocking (asynchronous) |
| Buffering |
• Zero capacity (no buffering) • Bounded capacity (finite buffer) • Unbounded capacity (infinite buffer) |
Endpoint for communication. Identified by IP address + port number.
Allows calling procedures on remote systems as if they were local.
Java mechanism similar to RPC for invoking methods on remote objects.
Q1. Which of the following is NOT stored in the PCB?
Q2. The main objective of multiprogramming is to improve:
Q3. When a process creates a new process using fork(), which is shared?
Q4. Context switch time is:
Q5. Explain the difference between long-term, medium-term, and short-term scheduling. (6 marks)
Q6. How many processes are created by this program? (4 marks)
2⁴ = 16 processes total (including the initial parent)
Each fork() doubles the number of processes.
Q7. What happens when a context switch occurs if the new context is already loaded in a register set? (3 marks)
If hardware provides multiple register sets and the new context is already loaded, the context switch is much faster - just switch the pointer to the active register set. No need to save/restore register values to/from memory.
| Term | Definition |
|---|---|
| Process | Program in execution; active entity with program counter |
| PCB | Process Control Block - data structure containing process information |
| Context Switch | Saving state of one process and loading state of another |
| fork() | System call that creates new process (child) in UNIX |
| exec() | System call that replaces process memory with new program |
| wait() | System call where parent waits for child to terminate |
| IPC | Interprocess Communication - mechanisms for process cooperation |
| Pipe | Unidirectional communication channel between processes |
| Ready Queue | List of processes ready and waiting to execute |
| Degree of Multiprogramming | Number of processes in memory |