OS Unit-1 23-24
OS Unit-1 23-24
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
4/89
Operating Systems - Unit-I February 24, 2024 4 / 89
Introduction Operating System Objectives
5/89
Operating Systems - Unit-I February 24, 2024 5 / 89
Introduction Operating System Objectives
OS Functionalities
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
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
12/89
Operating Systems - Unit-I February 24, 2024 12 / 89
Introduction Definition and Structure of OS
13/89
Operating Systems - Unit-I February 24, 2024 13 / 89
Introduction Definition and Structure of OS
14/89
Operating Systems - Unit-I February 24, 2024 14 / 89
Introduction Definition and Structure of OS
15/89
Operating Systems - Unit-I February 24, 2024 15 / 89
Introduction Definition and Structure of OS
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
18/89
Operating Systems - Unit-I February 24, 2024 18 / 89
Introduction Definition and Structure of OS
19/89
Operating Systems - Unit-I February 24, 2024 19 / 89
Introduction Definition and Structure of OS
20/89
Operating Systems - Unit-I February 24, 2024 20 / 89
OS-Structures Multiprogrammed OS
21/89
Operating Systems - Unit-I February 24, 2024 21 / 89
OS-Structures TimeShared OS
22/89
Operating Systems - Unit-I February 24, 2024 22 / 89
OS-Structures Personal Computer OS
23/89
Operating Systems - Unit-I February 24, 2024 23 / 89
OS-Structures Parallel OS
24/89
Operating Systems - Unit-I February 24, 2024 24 / 89
OS-Structures Distributed OS
26/89
Operating Systems - Unit-I February 24, 2024 26 / 89
OS-Operations and Functions OS-Operations
Operations - OS
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
30/89
Operating Systems - Unit-I February 24, 2024 30 / 89
OS-Operations and Functions Process Management
Process Management
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
33/89
Operating Systems - Unit-I February 24, 2024 33 / 89
OS-Operations and Functions Device Management and I/O Management
34/89
Operating Systems - Unit-I February 24, 2024 34 / 89
OS-Operations and Functions Device Management and I/O Management
35/89
Operating Systems - Unit-I February 24, 2024 35 / 89
OS-Operations and Functions File Management
File Management
36/89
Operating Systems - Unit-I February 24, 2024 36 / 89
OS-Operations and Functions File Management
File Management
37/89
Operating Systems - Unit-I February 24, 2024 37 / 89
OS-Operations and Functions Protection Security
Protection Security
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
40/89
Operating Systems - Unit-I February 24, 2024 40 / 89
OS Services I/O Operations
I/O Operations
41/89
Operating Systems - Unit-I February 24, 2024 41 / 89
OS Services File System manipulation
42/89
Operating Systems - Unit-I February 24, 2024 42 / 89
OS Services Communication
Communication
43/89
Operating Systems - Unit-I February 24, 2024 43 / 89
OS Services Error Handling
Error Handling
44/89
Operating Systems - Unit-I February 24, 2024 44 / 89
OS Services Resource Management
Resource Management
45/89
Operating Systems - Unit-I February 24, 2024 45 / 89
OS Services Protection
Protection
46/89
Operating Systems - Unit-I February 24, 2024 46 / 89
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
48/89
Operating Systems - Unit-I February 24, 2024 48 / 89
User and OS Interface Graphical User Interface
49/89
Operating Systems - Unit-I February 24, 2024 49 / 89
System Calls
System Calls
50/89
Operating Systems - Unit-I February 24, 2024 50 / 89
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
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
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
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
56/89
Operating Systems - Unit-I February 24, 2024 56 / 89
System Calls Types of System calls
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
58/89
Operating Systems - Unit-I February 24, 2024 58 / 89
System Calls System Programs
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
62/89
Operating Systems - Unit-I February 24, 2024 62 / 89
System Calls OS Design
63/89
Operating Systems - Unit-I February 24, 2024 63 / 89
System Calls 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
65/89
Operating Systems - Unit-I February 24, 2024 65 / 89
Process concepts
Process concepts
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
68/89
Operating Systems - Unit-I February 24, 2024 68 / 89
Process concepts Process State
69/89
Operating Systems - Unit-I February 24, 2024 69 / 89
Process concepts Process Control Block
70/89
Operating Systems - Unit-I February 24, 2024 70 / 89
Process concepts 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
72/89
Operating Systems - Unit-I February 24, 2024 72 / 89
Process concepts Threads
Threads
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
76/89
Operating Systems - Unit-I February 24, 2024 76 / 89
Process Scheduling Scheduling Queues
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
79/89
Operating Systems - Unit-I February 24, 2024 79 / 89
Process Scheduling Schedulers
80/89
Operating Systems - Unit-I February 24, 2024 80 / 89
Process Scheduling Schedulers
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
84/89
Operating Systems - Unit-I February 24, 2024 84 / 89
Operations on Processes Process Creation
85/89
Operating Systems - Unit-I February 24, 2024 85 / 89
Operations on Processes Process Creation
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