You are on page 1of 24

Tasneem Mirza

Introduction
Operating System: a system that manages the resources
of a computer.

Resources: CPUs, Memory, I/O devices, Network

Kernel: the memory resident portion of Unix system

File system and process control system are two major


components of Unix Kernel.
emacs
OS interacts directly with
sh who the hardware
Such OS is called
kernel date system kernel
cpp
ed
cc as hardware

ld wc

grep
nroff

Other apps
Three major tasks of kernel:
Process Management
Device Management
File Management
Three additional Services for Kernel:
Virtual Memory
Networking
Network File Systems
User Programs
Libraries
User Level
Kernel System Call Interface
Level
Inter-process
File Subsystem Process communication

control
Scheduler
subsystem
Device drivers
Memory
management

hardware control

hardware
Hardware Level
Unix process state
transition diagram
Note
1. User running state : When a process is executing user
code.
2. Kernel running state : when a process is executing a
system call.
Start in Created go to either:

Ready to Run, in Memory

or
Ready to Run, Swapped (Out) if there isnt room in
memory for the new process.
Ready to Run, in Memory is basically same state as
Preempted (dotted line)
When scheduled, go to either:
User Running (if in user mode)
or
Kernel Running (if in kernel mode)

Go from User running to Kernel running via


system call.
When a process is executing either its time slice
expires(preempted) or it finishes execution. Both
the transitions will be via kernel running state
since it is an OS code that the process has to
execute for both the transitions.
Note exit is a system call.
When a process executes a system call, it leaves the
state "user running" and enters the state kernel
running. Suppose a system call requires an I/O from
the disk and the process must wait for the I/O to
complete.
It enters the state asleep in memory (also called as
blocked state) putting itself to sleep until it is notified
that the I/O has completed.
When the I/O later completes, the hardware interrupts
the CPU, and the interrupt handler awakens the
process, causing it to enter the state ready to run in
memory .
If there is no space in memory then a process
which is in the asleep in memory state can be
swapped out and put on the secondary memory .
This state is called Sleep swapped.
When a process is in Sleep swapped state and
the event for eg I/O is completed then the
process moves to the state ready to run
swapped where it is still in the secondary
memory.
From ready to run swapped it could be swapped
back in memory and moves to a state Ready to
run in memory.
A process is the execution of a program and consists of a
pattern of bytes that the CPU interprets as machine
instructions (called "text") , data, and stack.
A process loaded in memory consists of 3 parts called regions
i.e text,data,stack
Two data structures describe the state of the process
1. Process table entry
2. U-area(user area)
Every process has an entry in the kernel process table, and
each process is allocated a u area that contains private data
manipulated only by the kernel. ,
Process table entry
Contains general fields of processes that must be
always be accessible to the kernel
U area
further characteristics of the process that only need to
be accessible to the running process itself.
Therefore the kernel allocates space for the u area only
when creating a process.
It does not need u-area for process table entries that
do not have processes.
Process table entry contains :
State field: user running, kernel running
etc.
Fields that allow the kernel to locate the
process and u area. Requires while context
switch
Process size : kernel know how much
space to allocate for the process.
User ID
Process ID

13
Event descriptor.
Used when the process is in the "sleep" state.
Scheduling parameters.
Allow the kernel to determine the order in
which processes move to the states "kernel
running" and "user running
A signal field.
keeps the signals sent to a process but not
yet handled.
Various timers: process execution time,
resource utilization etc.

14
U area contains :
A pointer to the process table entry
User IDs
various Timer:
Execution time in user mode
Execution Time in kernel mode
An error field: keeps error during system
call
Return value field: result of system call

15
I/O parameters
Amount of data transfer
Address of source and target etc.
The current directory and current root
User file descriptor table records files the
process has opened.
Limit fields
Restrict process size
Restrict size of the file it can write
The control terminal field:
login terminal associated with the process, if one exists
An array indicates how the process wishes to
react to signal

16
The process table contains (or points to) a per process region
table(pregion), whose entries point to entries in a region
table.
A region is a contiguous area of a process's address space,
such as text, data, and stack. Region table entries describe
the attributes of the region, such as whether it contains text
or data, whether it is shared or private, and where the "data"
of the region is located in memory.
The extra level of indirection (from the per process region
table to the region table) allows independent processes to
share regions.
Note:Several processes can share a region. For instance,
several processes may execute the same program, and it is
natural that they share one copy of the text region.
Kernel Process Kernel Region
Table A Process Table

Per Process Region Table

Text

File Descriptor Table Data

Stack
U Area
18
Note :
Information as to where each processs data,
text and stack segment is stored is in the
kernel region table.
There is only one kernel region table.
Per process region table will have information
as to where in the kernel table the processs
text, data and stack segment are stored.
Process Region
table table

text

data

stack

Active process

text

data

Diagram showing stack


Sharing of text region
Per-process
region table 20
The scheduler on the UNIX system belongs to the
general class of operating system schedulers
known as round robin with multilevel feedback,
meaning that the kernel allocates the CPU to a
process for a time quantum, preempts a process
that exceeds its time quantum, and feeds it back
into one of several priority queues.
A process may need many iterations through the
"feedback loop" before it finishes.
CPU scheduler keeps queues for each priority
Processes in user mode have positive priorities
Processes in kernel mode have negative priorities
(lower is higher)
Operating Systems 2013 - Michael 10/5/2017 23
Elhadad, Meni Adler& Amnon Meisels
Use round robin for each queue (separately)
Pick process from highest (non-empty) priority
queue
Run for 1 quantum (usually 100 ms.), or until it
blocks

You might also like