CSE3007
OPERATING SYSTEM
UNIT - II
Department of computer Science and Engineering SCHOOL OF ENGINEERING
Course Content
Course Content/SyllabusUnit I Introduction 8 lectures
Introduction to Operating System Concepts (including Multitasking, multiprogramming, multi user, Multithreading etc)., Classification of Operating systems- Batch, Time sharing, Real Time System, Distributed OS, Network OS, Real Time OS; Various Operating system services, architecture, System programs and calls
Unit II Process Management 8 lectures
Process concept, process scheduling, operation on processes; CPU scheduling, scheduling criteria, scheduling algorithms -First Come First Serve (FCFS), Shortest-Job-First (SJF), Priority Scheduling, Round Robin(RR), Multilevel Queue Scheduling
Unit III Memory Management 7 lectures
Logical & Physical Address Space, swapping, contiguous memory allocation, non-contiguous memory allocation paging and segmentation techniques, segmentation with paging; virtual memory management - Demand Paging & Page-Replacement Algorithms; Demand Segmentation.
Unit IV File System 8 lectures
Different types of files and their access methods, directory structures, various allocation methods, disk scheduling and management and its associated algorithms, Introduction to distributed file system.
Critical Section Problems, semaphores; methods for handling deadlocks-deadlock prevention, avoidance & detection; deadlock recovery.
Unit V I/O Systems 8 lectures
I/O Hardware, Application I/O Interface, Kernel, Transforming I/O requests, Performance Issues.
PROCESS
INTRODUCTION A process is a program in execution.
A process is more than the program code, which is sometimes
known as the text section.
It also includes the current activity, as represented by the value
PROCESS STATE
INTRODUCTION• As a process executes, it changes state. The state of a process
is defined in part by the current activity of that process.
– new: The process is being created
– running: Instructions are being executed
– waiting: The process is waiting for some event to occur – ready: The process is waiting to be assigned to a
processor
CONTEXT SWITCHING
When CPU switches to another process, the system must save
the state of the old process and load the saved state for the new process via a context switch
Context of a process represented in the PCB
Context-switch time is overhead; the system does no useful
work while switching
The more complex the OS and the PCB the longer the context switch
Time dependent on hardware support
Some hardware provides multiple sets of registers per CPU
PROCESS SCHEDULING
The objective of multiprogramming is to have some process running at all times, so as to maximize CPU utilization.
PROCESS SCHEDULING – Scheduling Queues
Maintains scheduling queues of processes
Job queue – set of all processes in the system
Ready queue – set of all processes residing in main memory,
ready and waiting to execute
Device queues – set of processes waiting for an I/O device
Processes migrate among the various queues
Representation of Process Scheduling
Operations on Processes
The processes in most systems can execute concurrently, and
they may be created and deleted dynamically. Thus, these systems must provide a mechanism for process creation and termination.
Two main operations on processes are:
1. Process Creation
Operations on Processes – Process Creation
A process may create several new processes, via a create –
process system call, during the course of execution.
The creating process is called a parent process, and the new
processes are called the children of that process.
Each of these new processes may in turn create other
processes, forming a tree of processes.
Generally, process identified and managed via a process
Operations on Processes – Process Creation
• Resource sharing options
• Parent and children share all resources
• Children share subset of parent’s resources – this
restriction avoids system overloading
•Execution options
Process Creation
fork() creates a duplicate of the current process
exec() replaces the program in the current process with another
Operations on Processes – Process Deletion
• Some operating systems do not allow child to exists if its parent has terminated.
• If a process terminates, then all its children must also be terminated.
• cascading termination. All children, grandchildren, etc. are terminated.
The termination is initiated by the operating system.
The parent process may wait for termination of a child process by using the
wait()system call. The call returns status information and the pid of the terminated
process
Operations on Processes – Process Deletion
If no parent waiting (did not invoke wait()) process is a zombie
A process which has finished the execution but still has entry in the process table to
report to its parent process is known as a zombie process. A child process always
first becomes a zombie before being removed from the process table. The parent
process reads the exit status of the child process which reaps off the child process
entry from the process table.
If parent terminated without invoking wait , process is an orphan
A process whose parent process no more exists i.e. either finished or terminated
Schedulers
A process migrates among the various scheduling queues
throughout its lifetime. The operating system must select, for
scheduling purposes, processes from these queues in some
fashion. The selection process is carried out by the appropriate
Schedulers
Long-term scheduler (or job scheduler) – selects from job
queue which processes should be brought into the ready queue Long-term scheduler is invoked infrequently (seconds,
minutes) (may be slow)
The long-term scheduler controls the degree of
multiprogramming
Short-term scheduler (or CPU scheduler) – selects from the
ready queue which processes should be executed next and allocates CPU
Sometimes the only scheduler in a system
Schedulers
Processes can be described as either:
I/O-bound process – spends more time doing I/O than computations, many short CPU bursts
CPU-bound process – spends more time doing computations; few very long CPU bursts
Long-term scheduler strives for good process mix otherwise the
Addition of Medium Term Scheduling
Medium-term scheduler can be added if degree of multiple
programming needs to decrease
Dispatcher
The dispatcher module gives control of the CPU to the process
selected by the short-term scheduler; this involves: switching context
switching to user mode
jumping to the proper location in the user program to restart that program
The dispatcher needs to run as fast as possible, since it is
invoked during process context switch
The time it takes for the dispatcher to stop one process and
Although the SJF algorithm is optimal, in that it gives the minimal average waiting time for a given set of processes, it cannot be implemented at the level of short term CPU scheduling. There is no way to know the length of the next CPU burst.
Priority Scheduling
• A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority. • Equal priority processes are scheduled in FCFS order.
• Priority are generally some fixed range of numbers such as from
0 to 7, or from 0 to 4095. However, there is no general agreement on whether 0 is the highest or lowest priority.
• Some systems use low numbers to represent low priority;
others use low numbers to represent high priority,
Priority scheduling
• Priority scheduling can be either pre-emptive or non-preemptive – A pre-emptive 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
Priority Scheduling
•
For example, if priorities range from 127 (low)
to 0 (high)., we could decrement the priority
Priority Scheduling
• This method is quite same as the SJF but the difference is that
instead of choosing the next process to work on by the shortest
burst time, CPU chooses the next process by the shortest priority
value. Here, all the processes are given a priority value. The process
with the shortest (The most shortest is 1) priority will be worked on
first and so on. Now consider a CPU and also consider a list in which