OS UNIT-I
OS UNIT-I
OS UNIT-I
UNIT -I
Computer System and Operating System
Overview:
• Overview of Computer System hardware.
• Operating System Objectives and functions.
• Operating System Services.
• System Calls.
• System Programs.
2
What is an Operating System?
• A program that acts as an intermediary between a user of a
computer and the computer hardware
3
• Computer System Overview
• No needless waiting
• T2 >> T1
• Thus, the hit ratio will be close to 1 even for a small cache.
Disk Cache (same
principles)
• A portion of main memory used as a buffer to
temporarily to hold data for the disk.
• Interrupt-drive I/O
• Direct Memory
Access
Programmed I/O
• I/O module performs action, not processor
• No interrupts occur
Control
Read/write
Test
Interrupt-driven I/O
• Objectives of OS
• Convenience
• Efficiency
• Ability to evolve
• Management of Systems Resources
•Convenience: An operating system works on the utilization of a
machine. It lets the user start with the processes that the user wants to
accomplish using the machine in a very quick manner without having
the stress of configuring the system first.
1. Security
The operating system helps in keeping the user data safe with help of protection
like passwords and some other similar methods, it is also capable of avoiding
unauthorized access to user data and programs.
2. Control over System Performance
The operating system acts as a watchdog over the system performance so that it
can be improved. It also keeps a record of the response time between when the
user has requested the service till the system responds back to have a complete
overview of the system's health. This data can help improve the performance of
the system by providing crucial information required for troubleshooting the
problems.
3. Job Accounting
The operating system keeps a track record of the time and resources consumed
by various tasks and users. That can further assist whenever there is a demand
for specific information.
c) Access to I/O devices: Each I/O device has its own instructions and control signals.
O.S takes care of these details and provides a simple interface to programmer.
• Process control
• File management
• Device management
• Information maintenance
• Communications
Types of System Calls
• Process control
• create process, terminate process
• end, abort
• load, execute
• get process attributes, set process attributes
• wait for time
• wait event, signal event
• allocate and free memory
• Dump memory if error
• Debugger for determining bugs, single step execution
• Locks for managing access to shared data between
processes
Types of System Calls
• File management
• create file, delete file
• open, close file
• read, write, reposition
• get and set file attributes
• Device management
• request device, release device
• read, write, reposition
• get device attributes, set device attributes
• logically attach or detach devices
Types of System Calls (Cont.)
• Information maintenance
• get time or date, set time or date
• get system data, set system data
• get and set process, file, or device attributes
• Communications
• create, delete communication connection
• send, receive messages if message passing model to host name or
process name
• From client to server
• Shared-memory model create and gain access to memory regions
• transfer status information
• attach and detach remote devices
System Programs
• System programs provide a convenient environment for program
development and execution. The can be divided into:
• File management
• Status information
• File modification
• Programming language support
• Program loading and execution
• Communications
• Application programs
• Most user’s view of the operation system is defined by system programs,
not the actual system calls.
• File management
These programs create, delete, copy, rename, print, dump, list, and generally
manipulate files and directories.
• Status information
Some programs simply ask the system for the date, time, amount of available memory
or disk space, number of users, or similar status information.
Others are more complex, providing detailed performance, logging, and debugging
information.
Typically, these programs format and print the output to the terminal or other output
devices or files or display it in a window of the graphical user interface (GUI).
Some systems also support a registry, which is used to store and retrieve configuration
information. 63
Programming-language support
Compilers, assemblers, debuggers, and interpreters for common
programming languages (such as C, C++, Java, and PERL) are often provided
with the operating system or available as a separate download.
64
Communications
These programs provide the mechanism for creating virtual connections
among processes, users, and computer systems.
They allow users to send messages to one another’s screens, to browse Web
pages, to send e-mail messages, to log in remotely, or to transfer files from
one machine to another.
Background services
All general-purpose systems have methods for launching certain system-
program processes at boot time. Some of these processes terminate after
completing their tasks, while others continue to run until the system is halted.
66
Operating Systems-IT508-IV-II 67
Two Suspend States
Scheduling and Process State Transitions
Nesting of Scheduling Functions
Basic Concepts
When processes arrive they are added to the tail of the queue.
When the CPU becomes free, the process in the head of the queue is
taken for execution.
When its CPU burst gets over, the process by itself relinquishes the CPU.
First-Come, First-Served (FCFS) Scheduling
P1 24
P2 3
P3 3
With FCFS, the process that requests the CPU first is allocated the CPU first
Case #1: Suppose that the processes arrive in the order: P ,P2,P3
1
0 24 27 30
P2 P3 P1
0 3 6 30
• Once the CPU has been allocated to a process, that process keeps the CPU
until it releases it either by terminating or by requesting I/O.
When the CPU becomes available, it is assigned to the process that has the
smallest next CPU burst (in the case of matching bursts, FCFS is used).
Two schemes:
Preemptive – if a new process arrives with a CPU burst length less than
the remaining time of the current executing process, preempt. This
scheme is know as the Shortest-Remaining-Time-First (SRTF).
Example #1: Non-Preemptive SJF (simultaneous arrival)
0 1 5 10 16
0 3 7 8 12 16
0 2 4 5 7 11 16
To estimate the length of next CPU burst using the length of previous CPU bursts
Operating Systems-IT508-IV-II 94
Priority
Scheduling
Priority Scheduling
• The SJF algorithm is a special case of the general priority scheduling
algorithm
• A priority number (integer) is associated with each process
• The CPU is allocated to the process with the highest priority (smallest
integer = highest priority)
• Priority scheduling can be either preemptive or non-preemptive
• A preemptive approach will preempt the CPU if the priority of the
newly-arrived process is higher than the priority of the currently
running process
• A non-preemptive approach will simply put the new process (with
the highest priority) at the head of the ready queue
• SJF is a priority scheduling algorithm where priority is the predicted
next CPU burst time
• The main problem with priority scheduling is starvation, that is, low
priority processes may never execute
• A solution is aging; as time progresses, the priority of a process in the
ready queue is increased
Round Robin (RR)
Scheduling
Round Robin (RR) Scheduling
• In the round robin algorithm, each process gets a small unit of CPU
time (a time quantum), usually 10-100 milliseconds. After this time
has elapsed, the process is preempted and added to the end of the
ready queue.
• If there are n processes in the ready queue and the time quantum is
q, then each process gets 1/n of the CPU time in chunks of at most q
time units at once. No process waits more than (n-1)q time units.
• Performance of the round robin algorithm
• q large FCFS
• q small q must be greater than the context switch time;
otherwise, the overhead is too high
• One rule of thumb is that 80% of the CPU bursts should be shorter
than the time quantum
Example of RR with Time Quantum = 20
Process Burst Time
P1 53
P2 17
P3 68
P4 24
• The Gantt chart is:
P1 P2 P3 P4 P1 P3 P4 P1 P3 P3
• Typically, higher average turnaround than SJF, but better response time
• Average waiting time
= ( [(0 – 0) + (77 - 20) + (121 – 97)] + (20 – 0) + [(37 – 0) + (97 - 57) + (134 – 117)] +
[(57 – 0) + (117 – 77)] ) / 4
= (0 + 57 + 24) + 20 + (37 + 40 + 17) + (57 + 40) ) / 4
= (81 + 20 + 94 + 97)/4
= 292 / 4 = 73
• Average turn-around time = 134 + 37 + 162 + 121) / 4 = 113.5
Time Quantum and Context Switches
Turnaround Time Varies With The Time
Quantum
As can be seen from this graph, the average turnaround time of a set
of processes does not necessarily improve as the time quantum size
increases. In general, the average turnaround time can be improved
if most processes finish their next CPU burst in a single time quantum.
Multi-level Queue
Scheduling
Multi-level Queue Scheduling
• Multi-level queue scheduling is used when processes can be classified into groups
• For example, foreground (interactive) processes and background (batch)
processes
• The two types of processes have different response-time requirements and
so may have different scheduling needs.
• Also, foreground processes may have priority (externally defined) over
background processes
• A multi-level queue scheduling algorithm partitions the ready queue into several
separate queues.
• The processes are permanently assigned to one queue, generally based on some
property of the process such as memory size, process priority, or process type
• Each queue has its own scheduling algorithm
• The foreground queue might be scheduled using an RR algorithm
• The background queue might be scheduled using an FCFS algorithm
• In addition, there needs to be scheduling among the queues, which is commonly
implemented as fixed-priority pre-emptive scheduling
• The foreground queue may have absolute priority over the background queue
Multi-level Queue Scheduling
• One example of a multi-level queue are the five queues shown below.
• Each queue has absolute priority over lower priority queues.
• For example, no process in the batch queue can run unless the queues
above it are empty.
• However, this can result in starvation for the processes in the lower
priority queues.
Multilevel Queue Scheduling
• Another possibility is to time slice among the queues
• Number of queues
• Method used to determine which queue a process will enter when that process
needs service
Example of Multilevel Feedback Queue
• Scheduling
• A new job enters queue Q0 (RR) Q0
and is placed at the end. When it
gains the CPU, the job receives 8
milliseconds. If it does not finish
in 8 milliseconds, the job is
moved to the end of queue Q1. Q1