Os Mid Term Notes
Os Mid Term Notes
An Operating System (OS) is a collection of programs that acts as an interface between a user
of a computer and the computer hardware. The purpose of an operating system is to provide
an environment in which a user may execute the programs. Operating Systems are viewed as
resource managers.
• Primary Goal: Convenience
• Secondary Goal: Efficiency
An Operating System (OS) is like a manager for your computer. It helps users interact with
the computer's hardware, such as the processor, memory, and storage, and makes sure
everything runs smoothly.
Primary Goal (Convenience): The OS makes it easy for you to use the computer by
providing a user-friendly environment to run programs. Think of it as the system that
lets you open apps, save files, and use devices like printers without dealing with the
technical details.
Secondary Goal (Efficiency): The OS ensures that all resources (like memory and
CPU) are used efficiently so the computer runs fast and doesn’t waste energy or
processing power. It's like a traffic controller for all the activities happening in the
system.
In short, the OS makes using a computer easy and keeps everything running smoothly in the
background.
Here’s a simple breakdown of the key functions of an Operating System:
1. User-Friendly Command Interface: The OS provides an easy-to-use interface so
users can interact with the computer, like typing commands or clicking icons.
2. Communication Between Users: It allows different users to communicate, share
files, or send messages across the system or network.
3. File and Directory Management with Security: The OS helps create, manage, and
protect files and directories, ensuring data is kept safe and secure.
4. Input/Output (I/O) Handling: The OS takes care of all the complicated tasks
involved in using devices like printers, keyboards, and storage, so you don’t have to.
5. Access to Compilers: The OS provides tools (compilers) to convert high-level
programming languages into machine language that the computer can understand.
6. Program Loading: After a program is compiled, the OS loads it into memory so it
can be executed by the CPU.
7. Fair Access to CPU: When many processes are running, the OS ensures each gets a
fair share of the CPU time to run smoothly without interference.
8. Managing Storage and Devices: It allocates storage space and manages devices (like
hard drives or printers) to ensure efficient operation.
9. Long-Term Data Storage: The OS organises and stores user data in files so it can be
accessed later, even after turning off the computer.
10. Sharing and Protection of Resources: The OS allows multiple users to share system
resources while protecting those resources from unauthorized access or misuse.
In short, the OS manages everything from running programs to protecting your files, making
sure the computer operates efficiently and securely
Operations and functions of an operating system:
1. Process Management
What it does: The OS manages running programs (called processes). It decides which
process runs at a given time, makes sure processes don’t interfere with each other, and
handles starting and stopping them.
Example: When you're using a browser and a music player at the same time, the OS
manages both processes.
2. Memory Management
What it does: The OS keeps track of which part of the computer’s memory is being
used by which programs. It allocates memory when a program needs it and frees it up
when no longer needed.
Example: Opening a Word document — the OS assigns memory to hold the
document and the application.
6. Protection
What it does: The OS ensures that unauthorized users or programs cannot access the
system’s resources or data. It controls who can use the system and how they can
interact with it.
Example: Passwords on your computer or restrictions on specific files.
1. Batch Processing Operating System
Features:
1. Processes tasks in groups without user interaction.
2. Executes jobs sequentially, one after another.
3. Saves time by processing similar jobs together.
Simple Example: Payroll systems used by companies to calculate salaries in batches
once a month.
A system call is like a request made by a program to the operating system to perform a
specific task, such as accessing files, managing processes, or interacting with hardware. Since
user programs don't have direct access to the system's hardware or critical functions, they
need system calls to ask the operating system (kernel) to do these things for them.
Purpose:
1. Resource Access: Programs need system calls to use things like files, memory, or
devices because they can’t access them directly.
2. Abstraction: System calls simplify complex hardware tasks by providing easy-to-use
functions, so the program doesn’t need to deal with the hardware itself.
3. Security: System calls ensure that only safe and allowed operations are performed,
preventing user programs from accidentally or intentionally damaging the system.
Mechanism of System Calls:
1. Transition from User Mode to Kernel Mode:
o User Mode: When applications run in user mode, they have limited access to
system resources for security and stability. This mode prevents them from
directly interacting with hardware or performing critical tasks.
o Kernel Mode: The operating system's core (the kernel) runs in this mode with
full control over the system. When a program needs to perform a privileged
operation (like accessing hardware), it triggers a system call, and the system
switches from user mode to kernel mode.
2. System Call Invocation:
o Software Interrupt or Trap: To make a system call, the program triggers a
special signal (called a trap or software interrupt), which alerts the CPU to
switch to kernel mode.
o System Call Number: Each system call has a unique identifier, which the
program sends to the kernel to specify which operation it needs (like opening a
file, reading data, etc.).
o Arguments: The program also passes any needed information (like file
names, memory locations, or values) to the system call.
3. Execution and Return:
o Kernel Processing: The kernel performs the requested operation, such as
reading a file, managing memory, or communicating between processes.
o Result Return: Once the operation is done, the kernel sends back the result to
the program. This could be data, a success message, or an error code.
o Context Switch:k After the system call is processed, the system switches
back to user mode, restoring the program's original state so it can continue
running.
Performance Considerations:
1. Overhead:
o Context Switch: When a system call is made, the system has to switch
between user mode and kernel mode. This involves saving the current state
of the process and loading the new state, which takes time and resources.
o Latency: The delay caused by switching modes and performing the system
call can slow down performance, especially if the calls happen frequently.
Security and Reliability:
1. Security:
o System calls are designed to protect the system. Before executing any request,
the kernel (core of the OS) checks to ensure it's safe and that the program has
the right permissions. This prevents unauthorized access to important system
resources.
2. Reliability:
o The kernel handles errors during system calls. If something goes wrong, it
returns an error code to the program, helping it manage the issue without
crashing the system. This keeps the system stable.
Process Management:
A process is basically a running program. It's the program that's being executed by the
computer.
Here’s what a process involves:
1. A Program in Execution: A process is a program that's actually running, not just
sitting as code.
2. Asynchronous Activity: It works on its own and runs independently from other
processes.
3. Unit of Work: The operating system manages and schedules processes to use the
computer's resources.
A process is more than just the code. It’s an active thing, while a program (the code) is
passive. A process includes:
1. The Program Counter (PC), which tells the OS which part of the code it's currently
running.
2. The current registers of the processor (temporary data storage).
3. The variables and temporary data it’s using.
4. A process stack, which stores things like function calls and temporary data.
5. A section for global variables used by the program.
In summary, a process is a unit of work that the operating system handles, and it contains
everything needed for the program to run.
A Process Control Block (PCB) is like a file card that the operating system uses to keep
track of every process (program) running on your computer. It stores all the details the
operating system needs to manage that process.
Here’s what’s on the card:
1. Process ID: A unique number that identifies the process.
2. Priority: How important the process is, which helps decide when it gets to run.
3. State: Whether the process is ready to run, currently running, or paused.
4. CPU Info: Details about the process's use of the CPU.
5. Memory Info: What part of the computer’s memory the process is using.
6. I/O Info: Devices (like printers or keyboards) the process is using or waiting for.
7. File Info: Files the process is working with.
The operating system uses the PCB to manage each process and decide what to do with it.
Once the process finishes, the PCB is cleared out for use by another process.
a modern operating system allows several processes (programs) to run seemingly at the same
time, even though the CPU can only handle one at a time. Here's how it works:
1. Switching Between Processes: The operating system quickly switches the CPU
between different processes so that it looks like everything is running at once. This is
called concurrent execution.
2. Shared Resources: Some things, like memory, can be used by multiple processes at
the same time, but other resources (like the CPU) can only be used by one process at a
time. The operating system manages who gets access.
3. CPU Time Sharing: The CPU is shared by giving each process a little bit of time.
The operating system sets a timer (alarm) that makes the CPU stop after a few
microseconds. It then saves all the important information about the current process
(like where it left off) and switches to another process.
4. Resuming a Process: When the next process is selected, the operating system
restores the saved information and resumes that process from where it left off.
This process of switching is fast and efficient, allowing multiple programs to feel like they’re
running at the same time.
1. Process Creation:
Name: The operating system needs to know the name of the program to run as a new
process.
Process ID and PCB: When a new process is created, the system makes a Process
Control Block (PCB). This is a special data structure that tracks everything about the
process, like its resources and priority. Each PCB has a unique Process ID (PID).
Locate Program: The system finds the program on the disk and gets memory ready
for it in RAM.
Load Program: The program is loaded into memory, and the PCB is set up with the
starting address and initial values it needs.
Priority: The operating system assigns a priority level to the process, which helps
decide how important it is compared to other processes.
Schedule for Execution: Finally, the process is added to the schedule, meaning it will
be run when it's its turn.
2. Process State Transitions:
Processes can be in different states, such as:
o Ready: The process is waiting to be assigned to the CPU.
o Running: The process is currently being executed by the CPU.
o Waiting: The process is waiting for some event (like I/O) to complete before
it can continue.
3. Process Termination:
Normal Termination: This happens when a process finishes running successfully. It
can occur when the program reaches the end or when it explicitly calls an exit
command.
Abnormal Termination: This occurs if something goes wrong, such as an error or if
the process is killed by a signal. It can happen without the process finishing its task.
In summary, creating, managing, and ending processes involves setting them up, tracking
their states, and properly shutting them down when they finish or encounter issues.
Process Scheduling
Process Scheduling is how the operating system decides which process gets to use the CPU
and when.
Types of Process Schedulers
1. Long Term Scheduler (Job Scheduler):
o What it does: Chooses which processes get to enter the system and run.
o When it runs: Not very often, just to keep enough processes ready to use.
o Goal: To make sure the CPU has enough work to do.
2. Short Term Scheduler (CPU Scheduler):
o What it does: Picks which process in memory gets to use the CPU right now.
o When it runs: Very frequently, every few milliseconds.
o Goal: To keep the CPU busy and respond quickly to users.
3. Medium-Term Scheduler:
o What it does: Moves some processes out of memory temporarily to free up
space.
o When it runs: Sometimes, when the system is busy.
o Goal: To manage resources better and ensure important processes have
enough memory.
Summary
In short, process scheduling helps the operating system manage which processes run on the
CPU, ensuring everything runs smoothly and efficiently.
Objectives of Process Scheduling Algorithm
1. Maximize CPU Utilization:
o Keep the CPU as busy as possible so it doesn't sit idle.
2. Fair CPU Allocation:
o Make sure every process gets a fair chance to use the CPU.
3. Maximize Throughput:
o Complete as many processes as possible in a given time.
4. Minimize Turnaround Time:
o Reduce the total time taken for a process to finish from start to end.
5. Minimize Waiting Time:
o Keep the time a process spends waiting in line to a minimum, ensuring no
process is stuck waiting too long.
6. Minimize Response Time:
o Ensure that processes respond quickly, especially for user-facing tasks.
Terminology in CPU Scheduling
Arrival Time: The moment a process enters the queue to wait for CPU time.
Completion Time: When a process finishes its execution.
Burst Time: The amount of time the CPU needs to execute a process.
Turnaround Time:
o Definition: The total time taken for a process from arrival to completion.
o Formula:
Turnaround Time = Completion Time - Arrival Time
Waiting Time (W.T):
o Definition: The time a process spends waiting in the queue.
o Formula:
Waiting Time = Turnaround Time - Burst Time
Summary
In short, process scheduling aims to make CPU use efficient, fair, and responsive, while
specific terms help measure how well the system is performing.