You are on page 1of 40

Operating System

CHAPTER 3
Process Management

Department of Computer Technology

1
Syllabus
• Process Management
• 3.1 Processes - Concept, process, state, process
• control block.
• 3.2 Process scheduling - Scheduling queues,
• scheduler, context switch.
• 3.3 Operations on processes - creation, termination.
• 3.4 Inter process communication.
• 3.5 Threads - Benefits, user and kernel threads.
• 3.6 Multithreading Models -
• Many to one, one to one, many to many.
2
Learning Objectives:
• To understand
(1) Process Management
(2) Processes
(3) Process scheduling
(4) Operations on processes
(5) Inter process communication.
(6) Threads
(7) Multithreading Models
3
Process Concept
• Process – a program in execution; process
execution must progress in sequential fashion
• A process includes:
– program counter
– stack
– data section

4
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

5
Diagram of Process State

6
Process Control Block (PCB)
Information associated with each process
• Process state
• Program counter
• CPU registers
• CPU scheduling information
• Memory-management information
• Accounting information
• I/O status information

7
Process Control Block (PCB)

8
CPU Switch From Process to
Process

9
Process Scheduling Queues
• 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

10
Ready Queue And Various I/O
Device Queues

11
Representation of Process
Scheduling

12
Schedulers
• Long-term scheduler (or job scheduler) –
selects which processes should be brought into the
ready queue
• Short-term scheduler (or CPU scheduler) –
selects which process should be executed next and
allocates CPU

13
Addition of Medium Term
Scheduling

14
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
• Context-switch time is overhead; the system does
no useful work while switching
• Time dependent on hardware support

15
Operations on processes
- Process Creation
• Parent process create children processes, which, in
turn create other processes, forming a tree of
processes
• Resource sharing
– Parent and children share all resources
– Children share subset of parent’s resources
– Parent and child share no resources
• Execution
– Parent and children execute concurrently
– Parent waits until children terminate 16
Operations on processes
- Process Termination
• Process executes last statement and asks the
operating system to delete it (exit)
• Parent may terminate execution of children
processes (abort)
• Some operating system do not allow child to
continue if its parent terminates

17
Interprocess Communication (IPC)
• Mechanism for processes to communicate and to
synchronize their actions
• Message system – processes communicate with
each other without resorting to shared variables
• IPC facility provides two operations:
– send(message) – message size fixed or variable
– receive(message)
• If P and Q wish to communicate, they need to:
– establish a communication link between them
– exchange messages via send/receive
18
Communications Models

19
Direct Communication
• Processes must name each other explicitly:
– send (P, message) – send a message to process P
– receive(Q, message) – receive a message from process
Q
• Properties of communication link
– Links are established automatically
– A link is associated with exactly one pair of
communicating processes
– Between each pair there exists exactly one link
– The link may be unidirectional, but is usually bi-
directional 20
Indirect Communication

• Messages are directed and received from


mailboxes
– Each mailbox has a unique id
– Processes can communicate only if they share a
mailbox
• Properties of communication link
– Link established only if processes share a common
mailbox
– A link may be associated with many processes
21
Synchronization
• Message passing may be either blocking or non-blocking
• Blocking is considered synchronous
– Blocking send has the sender block until the message
is received.
– Blocking receive has the receiver block until a
message is available.

22
Synchronization (con..)
• Non-blocking is considered asynchronous
– Non-blocking send has the sender send the
message and continue.
– Non-blocking receive has the receiver receive a
valid message or null

23
Buffering
• Queue of messages attached to the link;
implemented in one of three ways
1. Zero capacity – 0 messages
Sender must wait for receiver (rendezvous)
2. Bounded capacity – finite length of n
messages
Sender must wait if link full
3. Unbounded capacity – infinite length
Sender never waits
24
Threads
Single and Multithreaded Processes

25
Benefits
• Responsiveness

• Resource Sharing

• Economy

• Utilization of MP Architectures

26
User Threads
• Thread management done by user-level threads
library

• Three primary thread libraries:


– POSIX Pthreads
– Win32 threads
– Java threads

27
Kernel Threads
• Supported by the Kernel

• Examples
– Windows XP/2000
– Solaris
– Linux
– Tru64 UNIX
– Mac OS X

28
Multithreading Models
• Many-to-One

• One-to-One

• Many-to-Many

29
Many-to-One
• Many user-level threads mapped to single kernel
thread
• Examples:
– Solaris Green Threads
– GNU Portable Threads

30
Many-to-One Model

31
One-to-One
• Each user-level thread maps to kernel thread
• Examples
– Windows NT/XP/2000
– Linux
– Solaris 9 and later

32
One-to-one Model

33
Many-to-Many Model

• Allows many user level threads to be


mapped to many kernel threads
• Allows the operating system to create a
sufficient number of kernel threads
• Solaris prior to version 9
• Windows NT/2000 with the ThreadFiber
package

34
Many-to-Many Model

35
Two-level Model
• Similar to M:M, except that it allows a
user thread to be bound to kernel thread
• Examples
– IRIX
– HP-UX
– Tru64 UNIX
– Solaris 8 and earlier

36
Two-level Model

37
Summary
* Process – a program in execution; process execution
must progress in sequential fashion
* Process states – New , running , waiting , ready ,
terminated. *
Process sc3838heduling - Scheduling queues ,
Scheduler , context switch.
* Operations on processes - creation, termination.

38
Summary (cont..)
* Inter process communication.
* Threads - Benefits, user and kernel threads.
* Multithreading Models -
Many to one, one to one, many to many.

39
REFERENCES
• Achyut S. Godbole Opearating Systems Tata
McGraw-Hill
• Silberschatz Galvin, Operating System John
Wiley & Sons (Asia)
• www.en.wikipedia.org

40

You might also like