Operating System
Operating System
1. Define Process:
A process is a program in execution. It includes the program code, program counter, stack,
data section, and resources.
• Create
• Read
• Write
• Delete
• Multitasking
• Resource management
• User interface
9. Define deadlock:
Deadlock is a state in which a set of processes are blocked because each process is holding a
resource and waiting for another.
• Name
• Type
• Size
• Location
• File name
• File type
• File size
[4 marks]
1] ‘Operating system is like a manager of the computer system’. Explain.
1. Process Management – Manages process creation, execution, and termination. Uses CPU
scheduling algorithms.
3. File Management – Organizes, stores, retrieves, and protects data on storage devices.
4. Device Management – Manages input and output devices using device drivers and I/O
controllers.
5. Security and Access Control – Prevents unauthorized access and ensures system protection.
6. User Interface Management – Provides CLI (Command Line Interface) or GUI (Graphical User
Interface) for user interaction.
Scheduling refers to the method by which work is assigned to resources that complete the work.
In OS, it primarily deals with assigning CPU time to different processes.
Short-term Scheduler:
Medium-term Scheduler:
• Performs swapping: Moves processes between main memory and secondary storage.
A Process Control Block (PCB) is a data structure used by the operating system to store all
information about a process. Each process has a unique PCB, and the OS uses this information
to track the process's status and manage execution.
Components:
1. Process State: Current state of the process (e.g., Ready, Running, Waiting, Terminated).
2. Program Counter (PC):Address of the next instruction to be executed for the process.
3. CPU Registers: Contents of all process-specific registers (like accumulator, base, stack
pointer, etc.).
4. CPU Scheduling information: Includes a process priority, pointer to scheduling queues, and
any other scheduling parameters.
5. Memory Management Information: Details about memory allocated to the process, such as
base and limit registers, page tables, or segment tables.
6. Accounting Information: Tracks CPU usage, time limits, process priority, job or user numbers
for accounting purposes.
7. I/O Status Information: List of I/O devices allocated to the process, open file tables, etc.
CPU Count Only one CPU is used. Two or more CPUs are used.
The Process State Diagram represents various states of a process during its lifetime and the
transitions between them.
States:
• Ready → Running
• Running → Waiting
• Waiting → Ready
• Running → Terminated
• Running → Ready
Occurs when fixed-sized memory blocks Occurs when free memory is scattered in
Cause
are assigned, but process uses less. small non-contiguous blocks.
Allocated block = 100 KB; Process size = 3 blocks of 10 KB free but no 30 KB block
Example
80 KB ⇒ 20 KB wasted inside the block. available ⇒ process can't fit.
Wastage is internal to the partition, not Wastage is external, visible as small free
Visibility
easily visible. chunks.
Semaphores are basically integer variables that are modified atomically using two standard
operations:
Types of Semaphores:
1. Counting Semaphore:
o Value is either 0 or 1.
A deadlock occurs when a group of processes are waiting for each other in a circular chain, but none
can proceed.
1. Deadlock Prevention:
2. Deadlock Avoidance:
3. Deadlock Detection :
o Allow deadlocks to occur but detect them using Resource Allocation Graph (RAG).
4. Recovery:
1. Single-Level Directory:
o All files in a single directory.
2. Two-Level Directory:
3. Tree-Structured Directory:
o Hierarchical structure.
o Most common.
o Avoids cycles.
Linked Allocation is a file allocation method where each file is a linked list of disk blocks, which may
be scattered anywhere on the disk.
Working:
Advantages:
• No external fragmentation.
Disadvantages:
1. Stream of bytes :
o OS considers a file to be Unstructured.
o Simplifies file management for the OS. Applications can impose their own structure.
o Used by UNIX, windows and most modern OS.
2. Records :
o A file is a sequence of fixed length record, each with some internal structure.
o Collection of bytes is treated as a unit.
o Eg. Employee record.
3. Tree of records :
o A file consist of a tree of records, not necessarily all the same length.
o Records can be of variable length.
o Main Memory
o I/O Devices
2. Operating System:
• Includes:
o Compilers
o Assemblers
o Text Editors
o Database Systems
o User Applications
• These programs help users interact with the OS and hardware to perform useful tasks.
Contiguous Memory Allocation is one of the simplest and oldest memory management techniques
used in operating systems, where each process is allocated a single contiguous block of memory.
o The interrupt vector, which is often located in low memory, affects this decision.
o Typically, both OS and interrupt vector are placed in low memory for better
efficiency.
• When a process needs to be loaded, the system finds a large enough single block of free
memory.
• The entire process (code, data, stack) is placed in that continuous section.
• This method assumes that a process will not grow in size after allocation.
• Mutual Exclusion:
Only one process can enter the critical section at a time.
• Progress:
If no process is in the critical section, one of the waiting processes should be allowed to
enter next without unnecessary delay.
• Bounded Waiting:
A process must be guaranteed to enter the critical section after a bounded number of
attempts (to avoid starvation).
Access methods define the way data in a file can be read, written, or modified. The Operating
System provides different ways to access and retrieve data stored in files depending on the
application requirement.
1. Sequential Access
• Definition: Data in the file is accessed in a linear order, one record after another.
• Definition: Allows direct access to any block/record of the file using offset or position.
3. Indexed Access
• Definition: Uses an index to keep track of various blocks of a file. The index contains
pointers to the actual data blocks.
Paging is a memory management technique used to eliminate the problem of fitting varying sized
memory chunks onto the physical memory.
It allows the logical memory (used by programs) and physical memory (RAM) to be divided into
fixed-size blocks, making memory allocation efficient and reducing external fragmentation.
A Job Control Block (JCB) is a data structure maintained by the Operating System to manage and
track information about a job (or batch job) submitted by a user.
It is similar to the Process Control Block (PCB) used for processes, but the JCB is specifically used in
batch processing systems, where jobs are submitted and managed in queues.
Fields:
• Job ID
• Job Priority
• Program Counter
• CPU Registers
• I/O Requests
• Memory Requirements
2. Hold and Wait: Processes holding resources can wait for additional resources held by others.
3. No Preemption: Resources cannot be forcibly taken from a process; they must be released
voluntarily.
4. Circular Wait: A cycle of processes exists, where each process waits for a resource held by
another in the cycle.
1. Mutual Exclusion: Ensures resources are allocated exclusively to one process at a time.
2. Hold and Wait: Processes can hold resources while waiting for others, creating potential for
deadlock.
Fragmentation occurs when memory is inefficiently utilized due to allocation and deallocation of
processes in varying sizes. It is of two types:
1. External Fragmentation
o Paging: Using fixed-size blocks to avoid the need for contiguous memory.
2. Internal Fragmentation
• Wasted memory within allocated blocks when the allocated block is larger than needed by
the process.
The Dining Philosopher's Problem is a classic synchronization issue where five philosophers sit
at a table, each needing two forks to eat. There is one fork between each pair of philosophers.
Challenges:
1. Deadlock: If all philosophers pick up one fork simultaneously and wait for the other, no one
can eat.
2. Starvation: A philosopher might never get both forks if others keep taking them.
Solutions:
2. Arbitrator: A central controller decides who can eat, preventing deadlock and starvation.
Fragmentation occurs when memory is inefficiently utilized due to allocation and deallocation of
processes in varying sizes. It is of two types:
1. External Fragmentation
o Paging: Using fixed-size blocks to avoid the need for contiguous memory.
2. Internal Fragmentation
• Wasted memory within allocated blocks when the allocated block is larger than needed by
the process.
I/O Hardware enables communication between the computer and external devices, facilitating data
input, output, and storage.
o Examples: Hard Disk Drive (HDD), Solid State Drive (SSD), USB Flash Drive.
Each file has an index block which contains pointers to actual data blocks.
Diagram:
scss
CopyEdit
Index Block → [5, 9, 12, 15]
Blocks → [Data5][Data9][Data12][Data15]
Pros:
Cons:
Index block size limits file size. Indexed Allocation is a file storage method where each file has an
index block containing pointers to its data blocks, which can be scattered across the disk.
• A file is divided into blocks, and an index block holds pointers to these data blocks.
• The index block is stored separately and can point to multiple data blocks.
Types
1. Symmetric Multiprocessing (SMP): Multiple processors share a single memory and have
equal access to resources.
2. Asymmetric Multiprocessing (AMP): One master processor controls the system, while slave
processors handle specific tasks.
1. Process Termination:To break the deadlock, one or more processes involved are terminated.
2. Resource Preemption: Resources are forcibly taken from some processes and reallocated to
others to resolve deadlock.
Advantages:
Disadvantages:
1. Logical Address:
A logical address is the address generated by the CPU, used to access memory locations
independently of the actual physical location.
2. Physical Address:
A physical address is the actual address in the main memory (RAM) where data is stored.
32.List and explain system calls related to process and Job control.
1. End, Abort
2. Load, Execute
The Multilevel Feedback Queue (MLFQ) is a scheduling algorithm that uses multiple queues with
different priorities and allows processes to move between them based on their behavior.
An interrupt is a signal sent to the CPU to indicate that an event needs immediate attention. It
temporarily stops the current process, handles the event, and then resumes the previous process.
• Enables multitasking.
Types:
Free Space Management is the process of tracking available (free) and occupied space in storage to
efficiently allocate or deallocate space.
Bit Vector
A bit vector is an array of bits where each bit represents a block in storage:
• 1 = Block is occupied.
• 0 = Block is free.
Example: 10101100 means blocks 1, 3, 5, and 6 are occupied; blocks 2, 4, 7, and 8 are free.
Grouping
Grouping is an improvement over bit vectors, where instead of tracking each block individually,
groups of free blocks are stored with the starting block and the count of consecutive free blocks.
• Deadlock can be described more precisely in term of a directed graph called a system
resource allocation graph.
• A Resource Allocation Graph (RAG) is a directed graph used to represent the allocation of
resources in a system and is particularly useful in detecting deadlocks in a system. It shows
the relationship between processes and resources in a system.
3.Edges:
Process
Can be interrupted at any time. Cannot be interrupted once started.
Interruptions
1. Spooling:
Spooling (Simultaneous Peripheral Operations On-Line) is a process of placing data into a temporary
storage area (called a spool) to be accessed and processed by devices like printers or disk drives.
Spooling allows the CPU to continue processing while slower devices handle data transfer
sequentially.
• Compile-time binding: Addresses are determined at compile time, assuming that memory
will not change.
• Load-time binding: Addresses are determined when the program is loaded into memory.
• Execution-time binding: Addresses are determined during program execution, often using
dynamic memory allocation techniques.
7.Medium-Term Scheduler:
The medium-term scheduler is responsible for swapping processes in and out of memory. It works in
conjunction with the long-term and short-term schedulers to balance the degree of
multiprogramming. The medium-term scheduler temporarily removes processes from the CPU (swap
out) to free up memory and later swaps them back in (swap in) when resources become available.
8. Indexed Allocation:
Indexed allocation involves maintaining an index block for each file, where each index block contains
pointers to the actual data blocks of the file. This method eliminates fragmentation issues found in
contiguous allocation and allows for non-contiguous storage, but it requires additional space for
index blocks and increases access time.
• Peterson's Algorithm
• Semaphore-based solutions
• Monitors
• Mutex locks These methods ensure that only one process can be in its critical section at a
time and that other processes are appropriately synchronized.