unit3
unit3
1 PROCESS
PROCESS STATES PROCESS CONTROL BLOCK
PROCESS 3.2 PROCESS SCHEDULING
MANAGEMENT SCHEDULING QUEUES, SCHEDULERS, CONTEXT
SWITCH
( 14 Marks) 3.3 INTER-PROCESS COMMUNICATION (IPC)
INTRODUCTION, MESSAGE PASSING SYSTEM AND
SHARED MEMORY SYSTEM
3.4 THREADS: BENEFITS, USERS AND KERNEL
THREADS,
MULTITHREADING MODELS- MANY TO ONE, ONE TO
ONE, MANY TO MANY
3.5 EXECUTE PROCESS COMMANDS:
ps, wait, sleep, kill, exit
Process
A process is basically a program in
execution.
A process is defined as an entity which
Device Queue /
Blocked Queue
Schedulers
Definition –
• A process migrates between the various scheduling queues
throughout its life time. The operating system must select processes
from these queues by applying certain criteria.
The selection process is carried out by the appropriate scheduler.
• Scheduler is the system program which schedules processes from
the scheduling queues.
Types of Schedulers:
1. Long Term Scheduler
2. Short Term Scheduler
3. Medium Term Scheduler
Long Term Scheduler
It is also called job scheduler.
Long term scheduler determines which programs are admitted to
the system for processing.
Job scheduler selects processes from the queue and loads them
into memory for execution. Process loads into the memory for CPU
scheduling.
The primary objective of the job scheduler is to provide a balanced
mix of jobs, such as I/O bound and processor bound.
It also controls the degree of multiprogramming.
Time-sharing operating systems have no long term scheduler.
When process changes the state from new to ready, then there is
use of long term scheduler.
Short Term Scheduler (CPU Scheduler)
It is also called CPU scheduler.
It is the change of ready state to running state of the
process.
CPU scheduler selects process among the processes
scheduler.
Medium Term Scheduler
(Swapping Scheduler)
Medium term scheduling is part of the swapping.
It removes the processes from the memory.
Allow you to select It only selects processes that It helps you to send process
processes from the loads and is in a ready state of the back to memory.
pool back into the memory execution.
Convenience
Inter process communication
Shared memory
Message passing
• Message passing: Small amount of data, Easier to
implement
• Shared memory: Allow maximum speed, Convenience of
communication
Threads
A thread is called a lightweight process
It has separate path of execution
A Single process contains many threads
thread
Threads are executed simultaneously
Multithreading:
• It refers to the ability of an O.S to support multiple threads
of execution within asingle process.
• In a multi-threaded environment multiple processes and
multiple threads can be considered as in case of multiuser
O.S. such as UNIX.
E.g. Web Browser, Gmail etc.
Single thread vs Multithreads
Benefits of thread
User Threads
User Threads
Threads User
User space
Library space
Kernel
Kernel space
space
Kernel Threads
P
• OS managed threads.
• OS knows about and manages the thread.
User
• Kernel has a thread table which keeps tracks space
of all threads in the system. Kernel
space
• System calls create and manage threads.
Kernel Threads
• Slow and inefficient than user level.
• Hardware support is needed.
• Context switching time is more. Eg – P
Windows, Solaris etc.
Multithreading model
Many systems provide support for both user and kernel threads, resulting in
different multithreading models.
Following are three multithreading model:
Many to One
One to One
Many to Many
Many to One Multithreading model
• In the many-to-one model, many user-level
User Thread
threads are all mapped onto a single kernel
thread.
• Thread management is handled by the
thread library in user space, which is very
efficient.
• The entire process will block if a thread
makes a blocking system call.
• Because a single kernel thread can
access the kernel at a time, multiple
threads are unable to run in parallel on
multiple CPUs.
K Kernel Thread
• e.g. Green threads for Solaris ,GNU
Portable Threads.
One to One Multithreading model
The one-to-one model creates a separate
kernel thread to handle each user thread.
• Provides more concurrency than many-to-
one model by allowing another thread to run
when a thread makes a blocking call
• Also allows multiple threads to run in parallel User
Thread
across multiple CPUs.
• However the overhead of managing the
one-to-one model is more significant,
involving more overhead and slowing K K K K Kernel
down the system. Thread
• Most implementations of this model place
a limit on how many threads can be
created.
• Eg Linux and Windows NT/XP/2000.
Many to Many Multithreading model
The many-to-many model multiplexes
many user-level threads to a smaller
or equal number of kernel threads. User Thread
• sleep
• It is used to execute commands after certain
amount of time by sleeping for given seconds
• Eg
sleep 30
kill command
• kill
• The kill command can kill a process given its
process ID.
• Eg kill 1000
exit command
• exit
• The exit command is used to exit the shell where it is presently
running.
• Eg exit