Chap 2 Process Mangement
Chap 2 Process Mangement
Function stack –
Contains temporary
data ,
function parameter,
- Heap grow upside Local variable,
- stack grow downside Return variable
Dynamic Memory
allocated variable
Global variable /
static variable
Code Segment-
Instruction of
program
Process Concept
event to occur
Such as I/O completion or reception of a
signal.
ready: The process is waiting to be assigned
to a processor
terminated: The process has finished
execution
Terminat
e
exit
Secondary
Memory
New Main
Memory Ready
P1 P2 P3 running
P4 P5 P6
P1 P4 P7 CPU
Ready Queue
P7 P8 P9
Process state
The state may be new, ready, waiting, halted and so on. This
information is kept in a codified fashion in the PCB. That means it assigns
some numbers to each state and it stores that number so it requires very less
space.
Process number
At the time of process creation O.S allocates a number to the
process called process ID / number
Program counter
It indicates the address of the next instruction to be executed for
this process.
CPU registers
It vary in no of type depending on the computer architecture. They
include accumulators, index registers, stack pointers, any condition code
information. Along with the program counter the state information must be
saved when an interrupt occurs, to allow the process to be continued
Process Control Block (PCB)
CPU scheduling information
It includes a process priority, pointer to scheduling queues and any
other scheduling parameters.
Memory-management information
It includes information as the value of the base and limit registers,
the page tables or the segment tables, depending on the memory system used
by the O.S
Accounting information
It includes the amount real of CPU and time used time limits,
account numbers, job or process numbers and so on.
Short term
scheduler
New Job
Long term
scheduler
Job Needs
I/O
Job
finishes
with I/O
Long term Schedulers
It selects the batch job or process to be executed from a
secondary storage device and loads them into memory for
execution.
It is invoked when the process leaves the system.
Because of the longer duration between executions LTS can
afford to take more time to decide which process should be
selected for execution.
It also provide good process mix of I/O bound and CPU bound
processes to the Short term scheduler
The I/O bound process means the process require more I/O
than CPU
The CPU bound process means the process require more
CPU then I/O
System with the best performance will have a combination of
CPU bound and I/O bound processes.
Long term Schedulers
Functions of long term scheduler
1. It communicates directly with the job pool
2. It selects number of jobs from the pool and loads
them in the memory for execution. (degree of
multiprogramming is no. of programs, that can
reside in the memory of the computer at a time)
3. It need to be invoked only when a job leaves the
system. Therefore it is invoked less frequently as
compared to short term scheduler
4. It has the responsibility of selecting proper mix of
I/O bound and CPU bound jobs so that CPU
utilization is good.
Short term Schedulers
Interrupt cause the O.S to change a CPU from its current task to
run a kernel routine.
The process of switching the CPU from an old process to an
new process is called context switch.
When interrupt occurs, the system needs to save the current
context of the process currently running on the CPU so that it can
restore that context when its processing is done, essentially
suspending the process and then resuming it.
When a context switch occurs, the kernel saves the context of the
old process in its PCB and loads the saved context of the new
process scheduled to run.
It speed varies from M/C to M/C depending on the memory speed,
the no. of registers that must be copied and the existence of
special instruction.
Typical speeds are a few milliseconds.
Its times are highly dependent on H/W support.
Context Switch
Process P0
CPU Execution
CPU Switch From Process to Process
Operations on Process
UNIX examples
fork system call creates new process
If the child process is created the return code of
to the parent
execlp system call used after a fork to replace
currently executing
□ PC, registers, and stack
within a process
□ A thread is bound to a single process.
For each process, however, there may be many
threads.
□ Threads are the unit of scheduling
□ Processes are containers in which threads execute
Benefits of Multithreading
Programming
□ Responsiveness
□ Resource Sharing
□ Economy
□ Utilization Multiprocessor Architecture
Single and Multithreaded
Processes
Threads vs. Processes
User-Level Kernel-Level
□ Managed by application □ Managed by kernel
□ Kernel not aware of thread □ Consumes kernel resources
□ Context switching cheap □ Context switching expensive
□ Can create many more □ Number limited by kernel
□ Must be used with care resources
□ Simpler to use
4.1
Multithreading
Models
4.1
Many-to-One
□ Many user-level threads mapped to single kernel
thread
□ Threads Management is done by the thread library
in user space so it is efficient
Advantage
■ Fast - no system calls required
■ Few system dependencies;
■ portable
■Efficient : thread management is
done on the user level
Disadvantage:
The entire process will block if a thread makes a
blocking system call
Because only one thread can access the kernel at a
time multiple threads are unable to run in parallel on
multiprocessors
□ Examples:
■ Solaris Green Threads
■ GNU Portable Threads
4.1
One-to-One
connected to different kernel , if any user thread makes a blocking system call,
the other user threads won’t be blocked
■ Better multiprocessor performance – allows multiple threads to run
in parallel on multiprocessors
• disadvantage
■ Each user thread requires creation of kernel thread
■ Because the overhead of creating kernel threads can burden the
performance of an application (most implementation of the model
restrict the number of threads supported by the system
■ Each thread requires kernel resources;
■ limits number of total threads
□ Examples
■ Windows NT/XP/2000
4.1
Many-to-Many
Model
□ Allows many user level threads to be
mapped to many kernel threads
□ The number of kernel threads may be
specific to either a particular application
or particular machine
□ When a thread performs a blocking
system call, the kernel can schedule
another thread for execution.
■ Allows the operating system to create a
sufficient number of kernel threads
■ If U < L, no benefits of multithreading
■ If U > L, some threads may have to wait
for an LWP to run
□ Examples:
■ Solaris prior to version 9
■ Windows NT/2000 with the ThreadFiber
package
Two-level
Model
4.1