0% found this document useful (0 votes)
25 views89 pages

OS Unit-1 23-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views89 pages

OS Unit-1 23-24

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

Operating Systems - Unit-I

Introduction to Operating Systems ; Process

February 24, 2024

1/89
Operating Systems - Unit-I February 24, 2024 1 / 89
Unit-I Syllabus

Operating System
Introduction
Structures
Simple Batch operating systems
Multi programmed Systems
Timeshared systems
Personal Computer systems
Parallel systems
Distributed Systems
Real-Time Systems
System components
Operating System services
System Calls

2/89
Operating Systems - Unit-I February 24, 2024 2 / 89
Unit-I Syllabus

Process
Process concepts and scheduling
Operations on processes
Cooperating Processes
ThreadsOverview-Introduction

3/89
Operating Systems - Unit-I February 24, 2024 3 / 89
Introduction Introduction

Introduction

Operating System is a program that acts as an intermediary between


a user of a computer and the computer hardware

Operating system Goals:


Execute user programs and make solving user problems easier
Make the computer system convenient to use
Use the computer hardware in an efficient manner

4/89
Operating Systems - Unit-I February 24, 2024 4 / 89
Introduction Operating System Objectives

Operating System Objectives

1 Convenience: An OS makes a computer more convenient to use.


2 Efficiency: An OS allows the computer system resources to be used
in an efficient manner.
3 Ability to evolve: An OS should be constructed in such a way as to
permit the effective development, testing, and introduction of new
system functions without interfering with service.

5/89
Operating Systems - Unit-I February 24, 2024 5 / 89
Introduction Operating System Objectives

OS Functionalities

OS works as a User Computer Interface


OS works as a Resource Manager

6/89
Operating Systems - Unit-I February 24, 2024 6 / 89
Introduction Operating System Objectives

OS as User-System Interface

7/89
Operating Systems - Unit-I February 24, 2024 7 / 89
Introduction Operating System Objectives

OS as Resource Manager

8/89
Operating Systems - Unit-I February 24, 2024 8 / 89
Introduction Operating System Objectives

Ease of Evaluation of OS

A major OS will evolve over time for no of reasons.


Hardware upgrades plus new types of hardware.
New services
Fixes
The need to change OS regularly places certain requirements on its
design.
System should be modular in construction
System should be well documented.

9/89
Operating Systems - Unit-I February 24, 2024 9 / 89
Introduction OS-Userview

OS-Userview

Abstract Machine
Hides complex details of the underlying hardware
Provides common API to applications and services
Simplifies application writing
Command Interpreter
Part of a OS that understands and executes commands that are
entered interactively by a human being or from a program
Shell
In Single user system, user wants convenience, ease of use and wont
care about the resource utilization
In Shared computer system, such as mainframe must keep all users
happy so it make responce time minimum

10/89
Operating Systems - Unit-I February 24, 2024 10 / 89
Introduction OS-Systemview

OS-System View

OS is a resource allocator
Manages all resources
Decides between conflicting requests for efficient and fair resource use
OS is a control program
Controls execution of programs to prevent errors and improper use of
the computer

11/89
Operating Systems - Unit-I February 24, 2024 11 / 89
Introduction Definition and Structure of OS

Definition of Operating System

An operating system (OS) is system software that manages computer


hardware, software resources, and provides common services for computer
programs.

12/89
Operating Systems - Unit-I February 24, 2024 12 / 89
Introduction Definition and Structure of OS

Structure of Operating System

General-purpose OS is very large program

Various ways to structure ones


Simple structure – MS-DOS
More complex – UNIX
Layered – an abstraction
Microkernel -Mach

13/89
Operating Systems - Unit-I February 24, 2024 13 / 89
Introduction Definition and Structure of OS

Simple Structure - MS-DOS

MS-DOS – written to provide the most functionality in the least


space
Not divided into modules
Although MS-DOS has some structure, its interfaces and levels of
functionality are not well separated

14/89
Operating Systems - Unit-I February 24, 2024 14 / 89
Introduction Definition and Structure of OS

Traditional Unix System Architecture

UNIX – limited by hardware functionality, the original UNIX operating


system had limited structuring. The UNIX OS consists of two
separable parts
Systems programs
The Kernel
Consists of everything below the system-call interface and above the
physical hardware
Provides the file system, CPU scheduling, memory management, and
other operating-system functions; a large number of functions for one
level

15/89
Operating Systems - Unit-I February 24, 2024 15 / 89
Introduction Definition and Structure of OS

Traditional Unix System Architecture

16/89
Operating Systems - Unit-I February 24, 2024 16 / 89
Introduction Definition and Structure of OS

Layered Approach

17/89
Operating Systems - Unit-I February 24, 2024 17 / 89
Introduction Definition and Structure of OS

Layered Approach

The operating system is divided into a number of layers (levels), each


built on top of lower layers. The bottom layer (layer 0), is the
hardware; the highest (layer N) is the user interface.
With modularity, layers are selected such that each uses functions
(operations) and services of only lower-level layers

18/89
Operating Systems - Unit-I February 24, 2024 18 / 89
Introduction Definition and Structure of OS

Micro-kernel System Structure

19/89
Operating Systems - Unit-I February 24, 2024 19 / 89
Introduction Definition and Structure of OS

Micro-kernel System Structure

Moves as much from the kernel into user space


Mach example of microkernel
Mac OS X kernel (Darwin) partly based on Mach
Communication takes place between user modules using message
passing
Benefits:
Easier to extend a microkernel
Easier to port the operating system to new architectures
More reliable (less code is running in kernel mode)
More secure
Detriments:
Performance overhead of user space to kernel space communication

20/89
Operating Systems - Unit-I February 24, 2024 20 / 89
OS-Structures Multiprogrammed OS

Structure of Operating System- Multi Programmed

Multiprogramming (Batch system) needed for efficiency


Single user cannot keep CPU and I/O devices busy at all times
Multiprogramming organizes jobs (code and data) so CPU always has
one to execute
A subset of total jobs in system is kept in memory
One job selected and run via job scheduling
When it has to wait (for I/O for example), OS switches to another job

21/89
Operating Systems - Unit-I February 24, 2024 21 / 89
OS-Structures TimeShared OS

Structure of Operating System- Time Shared

Timesharing (multitasking) is logical extension in which CPU


switches jobs so frequently that users can interact with each job while
it is running, creating interactive computing
Response time should be <1 second
Each user has at least one program executing in memory ->process
If several jobs ready to run at the same time CPU ->scheduling
If processes don’t fit in memory, swapping moves them in and out to
run
Virtual memory allows execution of processes not completely in memory

22/89
Operating Systems - Unit-I February 24, 2024 22 / 89
OS-Structures Personal Computer OS

Structure of Operating System- Personal Computer


Systems

Personal computer operating system provides a good interface to a


single user.
Personal computer operating systems are widely used for word
processing, spreadsheets and Internet access.
You can say that your laptops, computer systems, tablets etc. are
your personal computers and the operating system such as windows
7, windows 10, android, etc. are your personal computer operating
system.

23/89
Operating Systems - Unit-I February 24, 2024 23 / 89
OS-Structures Parallel OS

Structure of Operating System-Parallel Systems

Parallel processing requires multiple processors and all the processor


works simultaneously in the system. Here, the task is divided into
subparts and these subparts are then distributed among the available
processors in the system. Parallel processing completes the job on the
shortest possible time.
All the processors in the parallel processing environment should run
on the same operating system.
All processors here are tightly coupled and are packed in one casing.
All the processors in the system share the common secondary storage
like the hard disk. As this is the first place where the programs are to
be placed.

24/89
Operating Systems - Unit-I February 24, 2024 24 / 89
OS-Structures Distributed OS

Structure of Operating System- Distributed Systems

These types of the operating system is a recent advancement in the


world of computer technology and are being widely accepted all over
the world and, that too, with a great pace.
Various autonomous interconnected computers communicate with
each other using a shared communication network.
Independent systems possess their own memory unit and CPU.
These are referred to as loosely coupled systems or distributed
systems.
These system’s processors differ in size and function.
The major benefit of working with these systems is that it is always
possible that one user can access the files or software which are not
actually present on his system but some other system connected
within this network i.e., remote access is enabled within the devices
connected in that network.
25/89
Operating Systems - Unit-I February 24, 2024 25 / 89
OS-Structures RealTime OS

Structure of Operating System- Real Time Systems

It is developed for real-time applications where data should be


processed in a fixed, small duration of time.
It is used in an environment where multiple processes are supposed to
be accepted and processed in a short time.
RTOS requires quick input and immediate response, e.g., in a
petroleum refinery, if the temperate gets too high and crosses the
threshold value, there should be an immediate response to this
situation to avoid the explosion.
Similarly, this system is used to control scientific instruments, missile
launch systems, traffic lights control systems, air traffic control
systems, etc.

26/89
Operating Systems - Unit-I February 24, 2024 26 / 89
OS-Operations and Functions OS-Operations

Operations - OS

Must distinguish between the use level code and OS code


User mode and kernel mode
Mode bit provided by hardware
Provides ability to distinguish when system is running user code or
kernel code
System call changes mode to kernel, return from call resets it to user
Some instructions are designated as privilaged, only executable in
kernel mode.
whenever trap or interrupt occurs, hardware switches from user to
kernel mode.

27/89
Operating Systems - Unit-I February 24, 2024 27 / 89
OS-Operations and Functions OS-Operations

OS Operations

28/89
Operating Systems - Unit-I February 24, 2024 28 / 89
OS-Operations and Functions OS-Operations

OS Operations

29/89
Operating Systems - Unit-I February 24, 2024 29 / 89
OS-Operations and Functions OS-Functions

Functions of Operating Ststem

30/89
Operating Systems - Unit-I February 24, 2024 30 / 89
OS-Operations and Functions Process Management

Process Management

A process is a program in execution.


A process needs certain resources, including CPU time, memory, files,
and I/O devices to accomplish its task.
Simultaneous execution leads to multiple processes. Hence creation,
execution and termination of a process are the most basic
functionality of an OS
If processes are dependent, than they may try to share same
resources. thus task of process synchronization comes to the picture.
If processes are independent, than a due care needs to be taken to
avoid their overlapping in memory area.
Based on priority, it is important to allow more important processes to
execute first than others.

31/89
Operating Systems - Unit-I February 24, 2024 31 / 89
OS-Operations and Functions Memory Management

Memory Management

Memory is a large array of words or bytes, each with its own address.
It is a repository of quickly accessible data shared by the CPU and
I/O devices.
Main memory is a volatile storage device. When the computer made
turn off everything stored in RAM will be erased automatically.
In addition to the physical RAM installed in your computer, most
modern operating systems allow your computer to use a virtual
memory system. Virtual memory allows your computer to use part of
a permanent storage device (such as a hard disk) as extra memory.

32/89
Operating Systems - Unit-I February 24, 2024 32 / 89
OS-Operations and Functions Memory Management

Memory Management

The operating system is responsible for the following activities in


connections with memory management:
Keep track of which parts of memory are currently being used and by
whom.
Decide which processes to load when memory space becomes available.
Allocate and de-allocate memory space as needed.

33/89
Operating Systems - Unit-I February 24, 2024 33 / 89
OS-Operations and Functions Device Management and I/O Management

Device Management and I/O Management

Device controllers are components on the motherboard (or on


expansion cards) that act as an interface between the CPU and the
actual device.
Device drivers, which are the operating system software components
that interact with the devices controllers.
A special device (inside CPU) called the Interrupt Controller handles
the task of receiving interrupt requests and prioritizes them to be
forwarded to the processor.
Deadlocks can occur when two (or more) processes have control of
different I/O resources that are needed by the other processes, and
they are unwilling to give up control of the device.

34/89
Operating Systems - Unit-I February 24, 2024 34 / 89
OS-Operations and Functions Device Management and I/O Management

Device Management and I/O Management

It performs the following activities for device management.


Keeps tracks of all devices connected to system.
Designates a program responsible for every device known as
Input/output controller.
Decides which process gets access to a certain device and for how long.
Allocates devices in an effective and efficient way.
Deallocates devices when they are no longer required.

35/89
Operating Systems - Unit-I February 24, 2024 35 / 89
OS-Operations and Functions File Management

File Management

A file is a collection of related information defined by its creator.


File systems provide the conventions for the encoding, storage and
management of data on a storage device such as a hard disk.
FAT12 (floppy disks)
FAT16 (DOS and older versions of Windows)
FAT32 (older versions of Windows)
NTFS (newer versions of Windows)
EXT3 (Unix/Linux)
HFS+ (Max OS X)

36/89
Operating Systems - Unit-I February 24, 2024 36 / 89
OS-Operations and Functions File Management

File Management

The operating system is responsible for the following activities in


connections with file management:
File creation and deletion.
Directory creation and deletion.
Support of primitives for manipulating files and directories.
Mapping files onto secondary storage.
File backup on stable (nonvolatile) storage media.

37/89
Operating Systems - Unit-I February 24, 2024 37 / 89
OS-Operations and Functions Protection Security

Protection Security

The operating system uses password protection to protect user data


and similar other techniques.
It also prevents unauthorized access to programs and user data by
assigning access right permission to files and directories.
The owners of information stored in a multiuser or networked
computer system may want to control use of that information,
concurrent processes should not interfere with each other.

38/89
Operating Systems - Unit-I February 24, 2024 38 / 89
OS Services

OS Services

Program execution
I/O operations
File System manipulation
Communication
Error Detection
Resource Allocation
Protection

39/89
Operating Systems - Unit-I February 24, 2024 39 / 89
OS Services Program Execution

Program Execution

Loads a program into memory.


Executes the program.
Handles program’s execution.
Provides a mechanism for process synchronization.
Provides a mechanism for process communication.
Provides a mechanism for deadlock handling.

40/89
Operating Systems - Unit-I February 24, 2024 40 / 89
OS Services I/O Operations

I/O Operations

An I/O subsystem comprises of I/O devices and their corresponding


driver software. Drivers hide the peculiarities of specific hardware
devices from the users.
An Operating System manages the communication between user and
device drivers.
I/O operation means read or write operation with any file or any
specific I/O device.
Operating system provides the access to the required I/O device when
required.

41/89
Operating Systems - Unit-I February 24, 2024 41 / 89
OS Services File System manipulation

File System Manipilation

Program needs to read a file or write a file.


The operating system gives the permission to the program for
operation on file.
Permission varies from read-only, read-write, denied and so on.
Operating System provides an interface to the user to create/delete
files.
Operating System provides an interface to the user to create/delete
directories.
Operating System provides an interface to create the backup of file
system.

42/89
Operating Systems - Unit-I February 24, 2024 42 / 89
OS Services Communication

Communication

Two processes often require data to be transferred between them


Both the processes can be on one computer or on different
computers, but are connected through a computer network.
Communication may be implemented by two methods, either by
Shared Memory or by Message Passing.

43/89
Operating Systems - Unit-I February 24, 2024 43 / 89
OS Services Error Handling

Error Handling

The OS constantly checks for possible errors.


The OS takes an appropriate action to ensure correct and consistent
computing.

44/89
Operating Systems - Unit-I February 24, 2024 44 / 89
OS Services Resource Management

Resource Management

The OS manages all kinds of resources using schedulers.


CPU scheduling algorithms are used for better utilization of CPU.

45/89
Operating Systems - Unit-I February 24, 2024 45 / 89
OS Services Protection

Protection

The OS ensures that all access to system resources is controlled.


The OS ensures that external I/O devices are protected from invalid
access attempts.
The OS provides authentication features for each user by means of
passwords.

46/89
Operating Systems - Unit-I February 24, 2024 46 / 89
User and OS Interface

User and OS Interface

There are two fundamental approaches for users to interface with the
operating system.
a command-line interface.
a graphical user interface (GUI).

47/89
Operating Systems - Unit-I February 24, 2024 47 / 89
User and OS Interface Command Interpreter

Command Interpreter

Some operating systems include the command interpreter in the


kernel. Others, such as Windows XP and UNIX, treat the command
interpreter as a special program that is running when a job is initiated
or when a user first logs on.
On systems with multiple command interpreters to choose from, the
interpreters are known as shells.
For example, on UNIX and Linux systems, there are several different
shells a user may choose from.

48/89
Operating Systems - Unit-I February 24, 2024 48 / 89
User and OS Interface Graphical User Interface

Graphical User Interface

A second strategy for interfacing with the operating system is through


a user friendly graphical user interface (GUI).
Rather than having users directly enter commands via a
command-line interface, a GUI allows provides a mouse-based
window-and-menu system as an interface.
A GUI provides a desktop where the mouse is moved to position its
pointer on images, or icons, on the screen (the desktop) that
represent programs, files, directories—known as a folder—, and
system functions.
Graphical user interfaces first appeared due in part to research taking
place in the early 1970s at Xerox PARC research facility.

49/89
Operating Systems - Unit-I February 24, 2024 49 / 89
System Calls

System Calls

Programming interface to the services provided by the OS


Typically written in a high-level language (C or C++)
Mostly accessed by programs via a high-level Application
Programming Interface (API) rather than direct system call use
Three most common APIs are Win32 API for Windows, POSIX API
for POSIX-based systems (including virtually all versions of UNIX,
Linux, and Mac OS X), and Java API for the Java virtual machine
(JVM)
Note: the system-call names used are generic

50/89
Operating Systems - Unit-I February 24, 2024 50 / 89
System Calls

Example of System calls

System call sequence to copy the contents of one file to another file

51/89
Operating Systems - Unit-I February 24, 2024 51 / 89
System Calls Types of System calls

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

52/89
Operating Systems - Unit-I February 24, 2024 52 / 89
System Calls Types of System calls

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

53/89
Operating Systems - Unit-I February 24, 2024 53 / 89
System Calls Types of System calls

Types of SystemCalls

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

54/89
Operating Systems - Unit-I February 24, 2024 54 / 89
System Calls Types of System calls

Types of System Calls

Protection
Control access to resources
Get and set permissions
Allow and deny user access

55/89
Operating Systems - Unit-I February 24, 2024 55 / 89
System Calls Types of System calls

Example of Windows and Unix System Calls

56/89
Operating Systems - Unit-I February 24, 2024 56 / 89
System Calls Types of System calls

Example of Standard C Library

C program invoking printf() library call, which calls write() system call

57/89
Operating Systems - Unit-I February 24, 2024 57 / 89
System Calls System Programs

System Programs

System programs provide a convenient environment for Program


development and execution. They can be divided into:
File manipulation
Status information sometimes stored in a File modification
Programming language support
Program loading and execution
Communications
Background services
Application programs
Most users’ view of the operation system is defined by system
programs, not the actual system calls

58/89
Operating Systems - Unit-I February 24, 2024 58 / 89
System Calls System Programs

System Programs

Provide a convenient environment for Program development and


execution
Some of them are simply user interfaces to system calls; others are
considerably more complex
File management - Create, delete, copy, rename, print, dump, list,
and generally manipulate files and directories
Status information
Some ask the system for info - date, time, amount of available memory,
disk space, number of users
Others provide detailed performance, logging, and debugging
information
Typically, these programs format and print the output to the terminal
or other output devices
Some systems implement a registry - used to store and retrieve
configuration information
59/89
Operating Systems - Unit-I February 24, 2024 59 / 89
System Calls System Programs

System programs

File modification
Text editors to create and modify files
Special commands to search contents of files or perform
transformations of the text
Programming-language support - Compilers, assemblers, debuggers
and interpreters sometimes provided
Program loading and execution- Absolute loaders, relocatable loaders,
linkage editors, and overlay-loaders, debugging systems for
higher-level and machine language
Communications - Provide the mechanism for creating virtual
connections among processes, users, and computer systems
Allow users to send messages to one another’s screens, browse web
pages, send electronic-mail messages, log in remotely, transfer files
from one machine to another
60/89
Operating Systems - Unit-I February 24, 2024 60 / 89
System Calls System Programs

System programs

Background Services
Launch at boot time
Some for system startup, then terminate
Some from system boot to shutdown
Provide facilities like disk checking, process scheduling, error logging,
printing
Run in user context not kernel context
Known as services, subsystems, daemons
Application programs
Don’t pertain to system
Run by users
Not typically considered part of OS
Launched by command line, mouse click, finger poke

61/89
Operating Systems - Unit-I February 24, 2024 61 / 89
System Calls OS Design

Operating System Design

Design and Implementation of OS not “solvable”, but some


approaches have proven successful
Internal structure of different Operating Systems can vary widely
Start the design by defining goals and specifications
Affected by choice of hardware, type of system
User goals and System goals
User goals – operating system should be convenient to use, easy to
learn, reliable, safe, and fast
System goals – operating system should be easy to design, implement,
and maintain, as well as flexible, reliable, error-free, and efficient

62/89
Operating Systems - Unit-I February 24, 2024 62 / 89
System Calls OS Design

Operating System Design

Important principle to separate


Policy: What will be done?
Mechanism: How to do it?
Mechanisms determine how to do something, policies decide what will
be done
The separation of policy from mechanism is a very important
principle, it allows maximum flexibility if policy decisions are to be
changed later (example – timer)
Specifying and designing an OS is highly creative task of software
engineering

63/89
Operating Systems - Unit-I February 24, 2024 63 / 89
System Calls Implementation

Operating System Implementation

Much variation
Early OSes in assembly language
Then system programming languages like Algol, PL/1 Now C, C++
Usually a mix of languages
Lowest levels in assembly
Main body in C
Systems programs in C, C++, scripting languages like PERL, Python,
shell scripts
More high-level language easier to port to other hardware
But slower
Emulation can allow an OS to run on non-native hardware

64/89
Operating Systems - Unit-I February 24, 2024 64 / 89
Process concepts

Process concepts

An operating system executes a variety of programs:


Batch system – jobs
Time-shared systems – user programs or tasks
Textbook uses the terms job and process almost interchangeably
Process – a program in execution; process execution must progress in
sequential fashion
Multiple parts
The program code, also called text section
Current activity including program counter, processor registers
Stack containing temporary data
Function parameters, return addresses, local variables
Data section containing global variables
Heap containing memory dynamically allocated during run time

65/89
Operating Systems - Unit-I February 24, 2024 65 / 89
Process concepts

Process concepts

Program is passive entity stored on disk (executable file), process is


active
Program becomes process when executable file loaded into memory
Execution of program started via GUI mouse clicks, command line
entry of its name, etc
One program can be several processes
Consider multiple users executing the same program

66/89
Operating Systems - Unit-I February 24, 2024 66 / 89
Process concepts Process

Process in Memory

67/89
Operating Systems - Unit-I February 24, 2024 67 / 89
Process concepts Process State

Process State

As a process executes, it changes state


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
terminated: The process has finished execution

68/89
Operating Systems - Unit-I February 24, 2024 68 / 89
Process concepts Process State

Process State Diagram

69/89
Operating Systems - Unit-I February 24, 2024 69 / 89
Process concepts Process Control Block

Process Control Block

70/89
Operating Systems - Unit-I February 24, 2024 70 / 89
Process concepts Process Control Block

Process Control Block

Information associated with each process (also called task control block)
Process state – running, waiting, etc
Program counter – location of instruction to next execute
CPU registers – contents of all process-centric registers
CPU scheduling information- priorities, scheduling queue pointers
Memory-management information – memory allocated to the process
Accounting information – CPU used, clock time elapsed since start,
time limits
I/O status information – I/O devices allocated to process, list of open
files

71/89
Operating Systems - Unit-I February 24, 2024 71 / 89
Process concepts Process Control Block

CPU Switch from Process to Process

72/89
Operating Systems - Unit-I February 24, 2024 72 / 89
Process concepts Threads

Threads

So far, Process has a single thread of execution


Consider having multiple program counters per process
Multiple locations can execute at once
Multiple threads of control ->threads
Must then have storage for thread details, multiple program counters
in PCB

73/89
Operating Systems - Unit-I February 24, 2024 73 / 89
Process concepts Threads

Process Representation

74/89
Operating Systems - Unit-I February 24, 2024 74 / 89
Process Scheduling

Process Scheduling

Maximize CPU use, quickly switch processes onto CPU for time
sharing
Process scheduler selects among available processes for next
execution on CPU
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

75/89
Operating Systems - Unit-I February 24, 2024 75 / 89
Process Scheduling Scheduling Queues

Ready Queue and Various I/O device Queue

76/89
Operating Systems - Unit-I February 24, 2024 76 / 89
Process Scheduling Scheduling Queues

Representation of Process Scheduling

Queueing diagram represents queues, resources, flows

77/89
Operating Systems - Unit-I February 24, 2024 77 / 89
Process Scheduling Schedulers

Schedulers

Types of Schedulers:
Short-term Scheduler
Long-term Scheduler
Medium-Term Scheduler

78/89
Operating Systems - Unit-I February 24, 2024 78 / 89
Process Scheduling Schedulers

Short Term Scheduler

Short-term scheduler (or CPU scheduler) – selects which process


should be executed next and allocates CPU
Sometimes the only scheduler in a system
Short-term scheduler is invoked frequently (milliseconds) ->(must be
fast)

79/89
Operating Systems - Unit-I February 24, 2024 79 / 89
Process Scheduling Schedulers

Long Term Scheduler

Long-term scheduler (or job scheduler) – selects 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
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

80/89
Operating Systems - Unit-I February 24, 2024 80 / 89
Process Scheduling Schedulers

Medium Term Scheduler

Medium-term scheduler can be added if degree of multiple


programming needs to decrease
Remove process from memory, store on disk, bring back in from disk to
continue execution: swapping

81/89
Operating Systems - Unit-I February 24, 2024 81 / 89
Process Scheduling Context Switch

Context Switch

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
multiple contexts loaded at once

82/89
Operating Systems - Unit-I February 24, 2024 82 / 89
Operations on Processes

Operations on Processes

Process Creation
Process Termination

83/89
Operating Systems - Unit-I February 24, 2024 83 / 89
Operations on Processes Process Creation

Process Creation

Parent process create children processes, which, in turn create other


processes, forming a tree of processes
Generally, process identified and managed via a process identifier
(pid)
Resource sharing options
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution options
Parent and children execute concurrently
Parent waits until children terminate

84/89
Operating Systems - Unit-I February 24, 2024 84 / 89
Operations on Processes Process Creation

A Tree of Processes in Linux

85/89
Operating Systems - Unit-I February 24, 2024 85 / 89
Operations on Processes Process Creation

Process creation (Cont.)

Address space
Child duplicate of parent
Child has a program loaded into it
UNIX examples
fork() system call creates new process
exec() system call used after a fork() to replace the process’ memory
space with a new program

86/89
Operating Systems - Unit-I February 24, 2024 86 / 89
Operations on Processes Process Termination

Process Termination

Process executes last statement and then asks the operating system
to delete it using the exit() system call.
Returns status data from child to parent (via wait())
Process’ resources are deallocated by operating system
Parent may terminate the execution of children processes using the
abort() system call.
Some reasons for doing so:
Child has exceeded allocated resources
Task assigned to child is no longer required
The parent is exiting and the operating systems does not allow a child
to continue if its parent terminates

87/89
Operating Systems - Unit-I February 24, 2024 87 / 89
Operations on Processes Process Termination

Process Termination

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
pid = wait(& status);
If no parent waiting (did not invoke wait()) process is a zombie
If parent terminated without invoking wait , process is an orphan

88/89
Operating Systems - Unit-I February 24, 2024 88 / 89
Operations on Processes Example

Forking a Process

89/89
Operating Systems - Unit-I February 24, 2024 89 / 89

You might also like