0% found this document useful (0 votes)
6 views11 pages

Operating System

The document outlines key concepts in operating systems, including the differences between programs and processes, the role of Process Control Blocks (PCBs), and the objectives of operating systems. It discusses process synchronization, external fragmentation, context switching, and various deadlock handling mechanisms. Additionally, it covers device management techniques, file access methods, paging, and the major functions of an operating system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

Operating System

The document outlines key concepts in operating systems, including the differences between programs and processes, the role of Process Control Blocks (PCBs), and the objectives of operating systems. It discusses process synchronization, external fragmentation, context switching, and various deadlock handling mechanisms. Additionally, it covers device management techniques, file access methods, paging, and the major functions of an operating system.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1. a) compare between program and process.

Program Process
A program is a static set of instructions A process is a program in execution, including its
written to perform a task. current state and resources.
It is passive and does not change during It is active and dynamic, with a life cycle (start,
execution. running, termination).
b)Define PCB and show the attributes of PCB with diagram.

A Process Control Block (PCB) is a data structure used by the operating system to store all the
information about a process. It acts as the process’s identity card and helps the OS manage and
control processes efficiently.

Attributes of PCB:

Attribute Description
Process ID (PID) Unique identifier for the process
Process State Current state (e.g., ready, running, waiting)
Program Counter (PC) Address of the next instruction to be executed
Contents of CPU registers (accumulators, index registers,
CPU Registers
etc.)
CPU Scheduling Information Priority, scheduling queue pointers
Memory Management
Base and limit registers, page tables
Information
Accounting Information CPU usage, time limits, job or process numbers
I/O Status Information List of I/O devices allocated to the process

Diagram of PCB:
+------------------------------------+
| Process ID (PID) |
+------------------------------------+
| Process State |
+------------------------------------+
| Program Counter (PC) |
+------------------------------------+
| CPU Registers |
+------------------------------------+
| CPU Scheduling Information |
+------------------------------------+
| Memory Management Information |
+------------------------------------+
| Accounting Information |
+------------------------------------+
| I/O Status Information |

c)List the objectives of operating system?


1. Manage Hardware Resources: Efficiently control and allocate CPU, memory, I/O
devices, and storage.
2. Provide User Interface: Offer an easy and convenient way for users to interact with the
computer.
3. Execute and Manage Programs: Load, execute, and control programs ensuring smooth
multitasking.
4. File Management: Organize, store, retrieve, and protect data on storage devices.
5. Security and Access Control: Protect data and resources from unauthorized access.
6. Error Detection and Handling: Identify and respond to system errors to maintain
stability.
7. Resource Allocation: Fairly allocate resources among multiple users and processes.

d)What is process synchronization?

Process synchronization is a technique used in operating systems to coordinate the execution


of multiple processes so that they can access shared resources or data safely without
conflicts or inconsistencies.

It ensures that processes do not interfere with each other when accessing critical sections,
preventing issues like race conditions.

Example: Two processes updating a shared bank account balance must be synchronized to avoid
incorrect results.

e)Define external fragmentation.

External fragmentation occurs when free memory is divided into small, scattered blocks
over time, making it difficult to allocate contiguous memory for new processes even though total
free memory is sufficient.

Example: After several allocations and deallocations, free memory might be fragmented into
small pockets that cannot satisfy large memory requests.

f)What is context switching?

Context switching is the process by which the CPU saves the state (context) of a currently
running process and loads the state of another process to resume its execution.

This allows multiple processes to share the CPU efficiently, enabling multitasking.

Example: Switching from one application to another on your computer involves a context
switch by the operating system.

g)What are the kinds of operation that are possible on semaphore?


Two basic operations can be performed on a semaphore:

1. Wait (P) Operation:


o Decreases the semaphore value by 1.
o If the value becomes negative, the process is blocked until the semaphore is
positive again.
2. Signal (V) Operation:
o Increases the semaphore value by 1.
o If there are blocked processes, one of them is unblocked.

These operations help in process synchronization and avoiding race conditions.

h)Define deadlock.

A deadlock is a situation in a multitasking system where two or more processes are unable to
proceed because each is waiting for a resource held by the other, causing all of them to be
stuck indefinitely.

Example: Process A holds Resource 1 and waits for Resource 2, while Process B holds
Resource 2 and waits for Resource 1. Neither can proceed.

i)What do you mean by turnaround time? How we can calculate turnaround time?

Turnaround time is the total time taken for a process to complete after it has been submitted. It
includes waiting time, execution time, and any delays.

Formula to Calculate Turnaround Time:

Turnaround Time=Completion Time−Arrival Time

Where:

 Completion Time = Time at which process finishes execution


 Arrival Time = Time at which process enters the ready queue

Example:
If a process arrives at time 2 and completes at time 10,
Turnaround Time = 10 - 2 = 8 units.

j)Explain the disadvantages of FCFS algorithm?

1. Poor Average Waiting Time:


o Longer processes can delay shorter ones, causing high average waiting time.
2. Convoy Effect:
o Shorter processes get stuck waiting behind longer ones, leading to inefficient CPU
utilization.
3. Non-preemptive:
o Once a process starts, it runs to completion, which reduces system responsiveness.
4. Not Ideal for Time-Sharing Systems:
o FCFS doesn’t handle interactive or real-time tasks well because it can't preempt
running processes.

2. a) What is device management ? Explain the different techniques for device management with
example ?

Device Management is a key function of the operating system responsible for managing all
input/output (I/O) devices such as printers, disks, keyboards, and displays. It controls the
communication between hardware devices and software, ensuring efficient, safe, and fair usage
of devices.

Objectives of Device Management:

 To provide a uniform interface to different hardware devices.


 To allocate and deallocate devices to processes.
 To handle device communication and data transfer.
 To manage device errors and maintain security.
 To maximize device utilization and system performance.

Different Techniques for Device Management:

1. Programmed I/O (Polling):


o The CPU actively checks (polls) the status of the device to see if it is ready for
data transfer.
o Example: A printer connected to a computer where the CPU waits and checks if
the printer is ready before sending data.
o Pros: Simple to implement.
o Cons: Wastes CPU time as it keeps checking, causing inefficiency.
2. Interrupt-Driven I/O:
o The device interrupts the CPU when it is ready for data transfer, allowing the
CPU to perform other tasks instead of polling.
o Example: When a keyboard sends a keypress, it generates an interrupt to notify
the CPU.
o Pros: Efficient CPU usage.
o Cons: Complexity increases due to interrupt handling.
3. Direct Memory Access (DMA):
o A special controller transfers data directly between the device and memory
without CPU involvement. The CPU is only interrupted after the entire transfer
completes.
o Example: Disk drives use DMA to transfer large blocks of data to RAM.
o Pros: Reduces CPU load, fast data transfer.
o Cons: Requires more complex hardware support.
b)Explain process and its different states with block diagram.

A process is a program in execution. It is an active entity that requires resources such as CPU
time, memory, files, and I/O devices to perform tasks. It represents a unit of work in the
operating system.

Different States of a Process:

A process typically goes through several states during its lifecycle:

State Description
New: The process is being created.
Ready: The process is waiting to get CPU time for execution.
Running: The process is currently being executed by the CPU.
Waiting (Blocked): The process is waiting for an event or resource (e.g., I/O completion).
Terminated (Exit): The process has finished execution and is being removed.

Process State Transition Diagram:


+-------+
| New |
+---+---+
|
v
+---+---+ Dispatch
| Ready | --------------> [Running]
+---+---+ |
^ | Process completes
| v
| +----+-----+
|<-------------- | Terminated|
| +----------+
Process waiting ^
for resource |
| |
v |
+---+----+ <------------+
| Waiting |
+--------+

Explanation of Transitions:

 New → Ready: After creation, process moves to ready queue.


 Ready → Running: Scheduler dispatches process to CPU.
 Running → Waiting: Process waits for I/O or event.
 Waiting → Ready: Event completes, process moves back to ready.
 Running → Terminated: Process finishes execution.

d)List different types of file access methods, and demonstrate indexed sequential access methods
with its diagram.

Different Types of File Access Methods:

1. Sequential Access:
Data is accessed in a linear order, one record after another. Commonly used for tape
drives.
Example: Reading a text file from beginning to end.
2. Direct (Random) Access:
Data can be accessed directly at any location without reading the preceding data. Useful
for databases.
Example: Accessing a record in a database by its key.
3. Indexed Sequential Access:
Combines sequential and direct access by maintaining an index for faster searching while
allowing sequential access of data. Common in file systems and database systems.

Indexed Sequential Access Method (ISAM):

 Data records are stored sequentially on the disk.


 An index is maintained separately, which contains pointers to the blocks or records.
 To access a record, the system first searches the index, then directly accesses the data
block.
 Allows both fast sequential reading and quick direct lookup using the index.

Diagram of Indexed Sequential Access:


+--------------------+ +-------------------+
| Index Table | --> | Data Blocks on |
|--------------------| | Disk |
| Key1 -> Block 1 | |-------------------|
| Key2 -> Block 2 | --> | Record 1, Record 2|
| Key3 -> Block 3 | | Record 3, Record 4|
+--------------------+ +-------------------+

 Step 1: Search the key in the Index Table.


 Step 2: Use the pointer to jump directly to the relevant Data Block.
 Step 3: Access the record sequentially within that block if needed.

e)Illustrate different methods of deadlock handling mechanism.


Deadlocks occur when a set of processes are blocked because each process is holding a resource
and waiting for another resource held by some other process. Operating systems use various
methods to handle deadlocks:

1. Deadlock Prevention

 Objective: Ensure that at least one of the necessary conditions for deadlock cannot hold
(mutual exclusion, hold and wait, no preemption, circular wait).
 Techniques:
o Mutual Exclusion: Avoid if possible by using sharable resources.
o Hold and Wait: Require processes to request all resources at once or release held
resources before requesting more.
o No Preemption: Allow resources to be forcibly taken from processes.
o Circular Wait: Impose ordering on resource acquisition to prevent cycles.
 Advantage: Deadlocks are completely avoided.
 Disadvantage: Can lead to low resource utilization or reduced system throughput.

2. Deadlock Avoidance

 Objective: Dynamically analyze resource-allocation requests to ensure the system never


enters an unsafe state.
 Example: Banker’s Algorithm
o Keeps track of maximum resource needs of each process.
o Grants requests only if the system remains in a safe state.
 Advantage: Allows more concurrency compared to prevention.
 Disadvantage: Requires knowledge of maximum resource requirements in advance;
computationally expensive.

3. Deadlock Detection and Recovery

 Detection:
o The system does not restrict resource allocation.
o Periodically checks for deadlocks using resource allocation graphs or algorithms.
 Recovery Methods:
o Process Termination: Abort one or more processes involved in deadlock until
deadlock is resolved.
o Resource Preemption: Temporarily take resources from some processes and
allocate them to others.
 Advantage: No resource wastage; system maximizes resource use.
 Disadvantage: Overhead of detection algorithm and complexity in recovery.

4. Ignore Deadlock (Ostrich Algorithm)

 The system pretends deadlock never happens.


 Used in systems where deadlocks are very rare or consequences are minor.
 Advantage: No overhead.
 Disadvantage: Risk of system hang or process failure.

f)Write short notes on paging.

Paging is a memory management technique that divides the physical memory and logical
memory into fixed-size blocks called frames (physical memory) and pages (logical memory).

Key Points:

 Purpose: To eliminate external fragmentation and make efficient use of memory.


 How it works:
o The process’s logical address space is split into pages of equal size.
o Physical memory is divided into frames of the same size.
o Pages are loaded into any available frames in physical memory, which may be
non-contiguous.
 Address Translation:
o The logical address is divided into a page number and a page offset.
o The page number is used to find the corresponding frame in the page table.
o The frame number combined with the page offset gives the physical address.
 Advantages:
o Eliminates external fragmentation.
o Allows non-contiguous memory allocation.
o Simplifies memory management.
 Disadvantages:
o Introduces internal fragmentation (unused memory within frames).
o Requires extra memory for the page table.
o Slower access due to address translation (can be improved with TLB - Translation
Lookaside Buffer).

Example: If page size is 4 KB, a logical address with page number 2 and offset 1000 refers to
frame 2 at offset 1000 in physical memory.

g) Explain major functions of operating system.

An Operating System (OS) is the software that acts as an interface between computer hardware
and users, managing resources and providing services for computer programs. Its major
functions include:

1. Process Management

 Creates, schedules, and terminates processes.


 Manages process synchronization and communication.
 Handles multitasking and allocates CPU time.

2. Memory Management
 Allocates and deallocates memory spaces to processes.
 Manages physical and virtual memory.
 Keeps track of each byte in memory and handles swapping between main memory and
disk.

3. File System Management

 Manages files and directories on storage devices.


 Controls file creation, deletion, reading, writing, and access permissions.
 Maintains file metadata and handles storage allocation.

4. Device Management

 Controls and manages all input/output devices.


 Provides device drivers and interfaces.
 Handles buffering, caching, and spooling.

5. Security and Protection

 Ensures authorized access to resources.


 Protects data and resources from unauthorized users.
 Implements authentication and encryption mechanisms.

6. User Interface

 Provides command-line interface (CLI) or graphical user interface (GUI).


 Enables user interaction with the system and applications.

[Link] seven phases of complier with neat block diagram.

A compiler translates a program written in a high-level language into machine code. The
compilation process is divided into several phases, each responsible for a specific task.

|
v
+-------------+ +---------------+ +--------------+
+--------------+
| Lexical | ---> | Syntax | ---> | Semantic | ---> |
Intermediate |
| Analysis | | Analysis | | Analysis | | Code
|
+-------------+ +---------------+ +--------------+
+--------------+
|
v
+------------------+
| Code Optimization|
+------------------+
|
v
+------------------+
| Code Generation |
+------------------+
|
v
+------------------+
| Symbol Table |
+------------------+

1. Lexical Analysis

 Function: Reads source code and converts it into tokens (keywords, identifiers,
symbols).
 Output: Stream of tokens.
 Example: Converts int x = 10; into tokens: int, x, =, 10, ;.
 Tool: Lexical analyzer or scanner.

2. Syntax Analysis (Parsing)

 Function: Checks the token sequence against grammar rules to form a parse tree or
syntax tree.
 Output: Syntax tree showing hierarchical structure.
 Purpose: Detects syntax errors.
 Example: Validates the statement structure like assignment, loops, etc.

3. Semantic Analysis

 Function: Ensures that the parse tree follows semantic rules (type checking, variable
declaration).
 Output: Annotated syntax tree with type information.
 Example: Checking if variables are declared before use, type compatibility in
expressions.

4. Intermediate Code Generation

 Function: Translates the syntax tree into an intermediate code (like three-address code),
which is machine-independent.
 Purpose: Simplifies optimization and code generation phases.
 Example: Converts a = b + c into something like t1 = b + c; a = t1;.

5. Code Optimization

 Function: Improves intermediate code to make it efficient (reducing time or space).


 Types: Local (within basic blocks) and global (across blocks).
 Examples: Removing redundant calculations, dead code elimination.
6. Code Generation

 Function: Converts optimized intermediate code into target machine code or assembly.
 Output: Machine-level instructions.
 Considerations: Register allocation, instruction selection.

7. Symbol Table Managemen

 Throughout compilation, a symbol table stores information about identifiers: variable


names, types, scopes, memory locations.
 Essential for semantic analysis, code generation, and error detection.

You might also like