Operating System Structures, Services, and Processes
OS Structures
Monolithic
The first OS structure, built as a single program with subroutines linked together, allowing each routine to call any other.
Features:
- Construction based on separately compiled modules joined by a linker.
- No protections or privileges.
- Fast and efficient execution and management.
Hierarchical
Divides the OS into autonomous parts with well-defined interfaces.
Features:
- Processor planning.
- Memory management (monolithic, caching, etc.).
- Console/operator control.
- Input/output management.
- File/information management.
Virtual Machine
Presents a virtual machine mimicking the underlying real machine, but with added features and protection against abuse.
Client/Server
Distributes work differently. The kernel facilitates communication between clients and servers. Processes can be both clients and servers.
OS Services
- Program Implementation: Allows program execution.
- Input/Output: Enables interaction with devices.
- File Management: Provides easy access and organization of files.
- Resource Allocation: Resolves conflicts between users/processes competing for resources (e.g., semaphores).
- Accounting: Tracks resource usage by users.
- Protection: Safeguards against unwanted actions.
System Calls
Normal Termination
Returns control to the user upon process completion.
Abnormal Termination
Terminates a program due to an error, returning control to the shell with an error status.
Status Requests
Returns program control with requested information.
Resource Requests
Requests specific resources from the OS (e.g., HDD, printer).
Input/Output Requests
Similar to resource requests.
Exception Handling
Exceptions
Special events requiring CPU attention.
Types:
- Hardware Failures: Physical or electrical malfunctions.
- Software Failures: Errors like division by zero.
- Incorrect Data Entry: Requires data re-entry.
- Restricted Information Access Attempts: Checks for unauthorized access.
- Disallowed Instruction Execution Attempts: Prevents execution of forbidden instructions.
- Anomalous Events: Events without a defined OS response.
Anomalous Event Categories:
- Catastrophic Errors: Disable the system, requiring a restart.
- Unrecoverable Errors: Affect only the running process.
- Recoverable Errors: Allow for continued execution after adjustment.
Protections
Essential safeguards against errors and malicious users.
Types of Protection:
- Input/Output Protection: Drivers control data flow and handle errors.
- Memory Protection: Processes have allocated memory areas (address zones) and cannot access others. Boundary registers define limits.
- Processor Protection: Timeouts prevent infinite loops.
Processes
A set of routines managing processor, memory, I/O, and other resources. A running program with its environment.
PCB (Process Control Block)
A matrix storing process information, memory address, required resources, and process state.
Objectives:
- Process information location by the OS.
- Data maintenance for suspended or restarted processes.
Information in PCB:
- Process State: Active, Idle, Standby, or Zombie.
- Statistics and resource usage.
- Internal and external memory usage.
- Resources in use (I/O units).
- Files in use.
- Privileges.
Process States
PCBs are stored in queues representing different states (active, standby, etc.).
Active States:
- Running: Has processor control.
- Ready: Ready to run but waiting for higher-priority processes.
- Blocked: Waiting for resources.
Inactive States:
Cannot compete for processor control but can become active later.
Reasons for Suspension:
- Suspended/Blocked: Waiting for an event.
- Suspended/Ready: No blocking cause but not active.
Quantum
A unit of work.
Process Operations
- Create: Process = (program + data + arguments). Added to PCB queue.
- Delete: OS removes completed or inactive processes.
- Suspend: OS temporarily stops a process due to malfunction or overload.
- Change Priority: Adjusts process priority.
- Timed Execution: Executes a process at a specific time.
- Wake Up: Activates a suspended process when resources become available.
Priority Ranking
- OS Assigned: Allocated at process creation.
- User Assigned: User can modify priority.
Process Types
- Static: Cannot be modified at runtime.
- Dynamic: Can be modified during execution.
- Reusable: Can be used multiple times.
- Reentrant: Code-only processes that can be used by multiple users simultaneously.
- Appropriate Resources: Exclusive resource usage by a process.
- Non-Appropriate Resources: Shared resource usage.
- Resident: Remain in memory throughout OS kernel lifetime.
- Interchangeable: Can be paused, swapped, or removed if needed.
Planning
Objective
Provide good service to all processes.
Planning Levels
- Long-Term: Decides the next job to run.
- Medium-Term (Swapping): Decides whether to move blocked/suspended processes to secondary memory.
- Short-Term: Processor scheduling based on chosen policy.
Criteria for Scheduling Algorithm Selection
- Response Time: Speed of response to requests.
- Operating Time: Time from loading to removal from memory.
- Runtime: Theoretical time needed if run alone.
- Processor Time: Actual processor usage time.
- Waiting Time: Time spent in queue.
- Time Efficiency: Processor usage optimization.
- Time Performance: Jobs completed per unit of time.
Scheduling Algorithms
Preemptive Policies
Processes can be temporarily suspended.
Non-Preemptive Policies
Processes run to completion.
FCFS (First Come, First Served)
Non-preemptive, FIFO. Simple but poor performance. Predictable but average service length varies greatly.
Round-Robin
Preemptive, time-sharing. Efficient for low overhead context switching. Uniform service rate. Quantum size is crucial.
SJN (Shortest Job Next)
Non-preemptive. Runs the shortest job first. Requires knowing execution time, which is difficult to obtain accurately. Penalizes long processes.