Chapter 3
Operating System Concepts – Detailed Study Notes
1. Process Concept (3.1)
An operating system executes a variety of programs, which can be categorized into:
Batch System: Processes jobs in groups, or batches.
Time-Shared Systems: Allows multiple users to share a computer simultaneously.
The terms job and process are often used interchangeably in textbooks.
A Process is defined as:
A program in execution.
Process execution must progress sequentially.
Memory Layout of a Process:
Program Code: Also known as the text section.
Current Activity: Includes program counter and processor registers.
Stack Section: Contains temporary data, function parameters, return addresses, and local variables.
Data Section: Holds global variables.
Heap Section: Contains memory dynamically allocated during runtime.
2. Process Concept (Cont.) (3.2)
A process is an active entity created from a passive program stored on disk (executable file) when it is loaded into memory.
Execution of a program can be initiated through different user interactions like GUI mouse clicks or command line entries.
A single program can have multiple processes, especially when executed by different users.
3. Task Manager (3.3)
Process Explorer: A tool that can be downloaded to view both processes and threads on the system.
4. Process in Memory (3.4)
Breakdown of a process's memory sections:
Stack Section: Used for temporary data storage, function parameters, return addresses, and local variables.
Heap Section: Memory dynamically allocated during the program's runtime.
Data Section: Contains global variables.
Text Section: Contains the executable code.
5. Process State (3.5)
As a process executes, it transitions between several states:
new: The process is being created.
running: Instructions are currently being executed.
waiting: The process is waiting for some event, such as I/O completion.
ready: The process is waiting to be assigned to a CPU.
terminated: The process has finished its execution.
6. Process Control Block (PCB) (3.6)
Each process is represented by a Process Control Block (PCB) or task control block, which contains:
Process State: Current state of the process (e.g., running, waiting).
Program Counter: Contains location of the next instruction to be executed.
Process Number: A unique identifier (ID) for the process.
CPU Registers: Stores contents of all process-centric registers.
CPU Scheduling Information: Holds priorities and pointers to scheduling queues.
Memory Management Information: Details the memory allocation for the process.
Accounting Information: Includes CPU time used and clock time elapsed since the start.
I/O Status Information: Lists I/O devices allocated to the process and open files.
7. Process Scheduling (3.7)
Objectives:
Multiprogramming: Ensure some process is running at all times to maximize CPU utilization.
Time Sharing: Switch the CPU among processes frequently to allow user interaction.
The Process Scheduler:
Selects an available process for execution on the CPU.
For a single-processor system, only one process can run at a time; the others must wait.
8. Scheduling Queues (3.8)
The OS maintains different scheduling queues:
Job Queue: Contains all processes in the system as they enter.
Ready Queue: Processes residing in main memory, ready to execute.
9. Context Switch (3.9)
A context switch occurs when the OS interrupts the current task to run a kernel routine.
When this occurs, the current context of the running process must be saved.
The context is represented in the PCB of the process.
10. Context Switch (Cont.) (3.10)
Steps of switching the CPU to another process:
State save of the current process.
State restore of the new process via context switch.
Context-switch time: Considered overhead as no useful work is performed during this switch. It varies by machine, typically taking a few milliseconds.
11. Operations on Processes (3.11)
Processes may create new processes using create-process system call:
Parent Process: The original process.
Child Processes: New processes created by the parent.
These processes may create additional processes, forming a process tree.
Mechanisms provided by the system include process creation and termination.
Example: A web server creates a child process for each incoming user request, while continuing to handle new requests without blocking.
Example: Double-clicking a Word file triggers the Explorer process, which calls CreateProcess() to start WINWORD.EXE.
12. Interprocess Communication (IPC) (3.12)
Processes can be categorized into:
Independent Processes: Cannot affect or be affected by other processes.
Example: Running Word and playing music simultaneously.
Cooperating Processes: Can affect or be affected by other processes.
Example 1: A web browser rendering a PDF file through a plugin process.
Example 2: A chat app client and server processes communicating for message exchange.
13. Rationale for Process Cooperation (3.13)
Reasons for enabling cooperation among processes include:
Information Sharing:
Example: Shared database access in payroll and accounting applications.
Example: Google Docs collaboration.
Computation Speedup:
Example: Web servers like Apache create multiple worker processes to handle requests, speeding up overall response time.
Modularity:
Systems are divided into smaller, cooperating processes.
Convenience:
Backup processes can run simultaneously with other tasks.
14. IPC Mechanisms (3.14)
Allows cooperating processes to exchange data and information via:
Shared Memory:
Two processes map the same memory region.
Example: A video player process writes frames to shared memory for a display process to read.
Message Passing:
Processes send and receive messages through the OS.
Example: A chat app client sending a message to server and relaying it to another client.
15. Shared Memory IPC (3.15)
Involves:
Establishing a region of shared memory for communication.
Process attach/detach operations for the shared region.
Requires agreements between processes to overcome OS memory access restrictions.
Producer-consumer model where the producer creates information to be consumed by the consumer (e.g., server and client interactions).
16. Producer-Consumer Problem (3.18)
Strategies for concurrent operation include:
Example: Multimedia streaming with decoders and displayers using shared memory buffered frames.
Bufferring Requirement:
Allows producer to produce and consumer to consume concurrently.
Processes must be synchronized to avoid consuming unproduced items.
Buffer Types:
Unbounded Buffer: No limit on buffer size; consumers might wait for items.
Bounded Buffer: Fixed size buffer, consumers wait if empty, producers wait if full.
17. IPC via Message Passing (3.20)
Example Case 1: Email System.
Example Case 2: Chat Application.
Example Case 3: Distributed Systems where client-server architectures communicate.
Useful in environments where processes do not share memory.
18. Message Passing Operations (3.21)
Message-passing allows synchronization and data exchange between processes:
send(message) and receive(message) operations.
Messages can be fixed or variable in size.
Communication links must exist for processes to exchange messages.
19. Communication Link Establishment (3.22)
Processes must:
Establish a communication link.
Use either direct/indirect communication methods.
Choose between synchronous/asynchronous communication and buffering strategies.
20. Direct Communication (3.24)
Mechanism where processes name each other explicitly:
send(P, message): Sends a message to process P.
receive(Q, message): Receives message from process Q.
Link Properties: Automatic establishment, one pair of processes per link, and symmetry in addressing (both must name each other).
21. Asymmetrical Direct Communication (3.25)
A variation where only the sender names the recipient:
send(P, message): to process P.
receive(id, message): receiving from any process, with
idset to the sender's name.
Drawbacks reduced modularity in process definitions due to interdependencies.
22. Indirect Communication (3.26)
Messages sent to/from mailboxes (or ports):
Used for communication between processes that share the same mailbox.
Mailbox operations:
Creating a mailbox, sending and receiving messages, destroying a mailbox.
23. Mailbox Operations (3.27)
Primitives defined for mailbox operations include:
send(A, message): to mailbox A.
receive(A, message): from mailbox A.
24. Mailbox Sharing (3.28)
Scenarios include processes sharing a mailbox and determining which process receives a message based on specified methods:
Allow link association, per process or systematic selection via algorithm.
25. Synchronization in Message Passing (3.29)
Types of message passing are characterized by blocking or non-blocking:
Blocking (Synchronous): Sender blocked until receipt; receiver blocked until a message is available.
Example: Dialing a friend’s number and waiting.
Non-blocking (Asynchronous): Sender sends and moves on; receiver gets either a valid or null message.
Example: Sending a text message without waiting for a response.
26. Buffering in Message Passing (3.30)
Messages reside in a temporary queue (buffer) for smooth transfer:
Zero Capacity: No waiting messages; sender must wait.
Bounded Capacity: Fixed length limit; blocks sender if full.
Unbounded Capacity: Infinite space; sender never waits.
27. Sockets (3.31)
Fundamental to Client-Server communication, serving as communication endpoints:
Each socket identified by an IP address and port number.
A server listens on a specified port for client requests, completing connections upon receiving requests.
Well-known ports reserved (e.g., HTTP on port 80).
28. Socket Communication (3.32)
Defined by pairing sockets at each endpoint for communication.
Example: 161.25.19.8:1625 indicates the service endpoint for a host.
29. Client Request for Socket Communication (3.33)
Client processes request a connection and are assigned an arbitrary port number:
The packet delivery is based on the destination port number, ensuring correct message routing.