Вы находитесь на странице: 1из 29

PROCESSES

Lecture Series By :
Er. Kanwalvir Singh Dhindsa

Website ::
www.dhindsa.info

http://groups.google.com/group/os-2007

1
O.S. by Er. K.S.Dhindsa © 2007
Process Concept

 An operating system executes a variety of programs:


– Batch system –> jobs
– Time-shared systems –> user programs or tasks

 Process – a program in execution & having program counter specifying


the next instruction to execute process;

Execution must progress in sequential fashion;

Process is an active entity process includes:


–program counter
–stack
–data section;

• Program — Contents of file stored on disk;


& Program is an passive entity

2
O.S. by Er. K.S.Dhindsa © 2007
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

3
O.S. by Er. K.S.Dhindsa © 2007
Diagram of Process State

4
O.S. by Er. K.S.Dhindsa © 2007
Processes
• “A program in execution”
• Modern computers allow several at once
– “pseudoparallelism”

A A B C
A
Program B
B
Counter
Conceptual View C

C Time
5
O.S. by Er. K.S.Dhindsa © 2007
Unix Process Creation

• System call: fork()


– creates identical copy of process
– return value different for child/parent
• System call: exec()
– over-write with new process address space
• Shell
– uses fork() and exec()

6
O.S. by Er. K.S.Dhindsa © 2007
Process Scheduler

cat ls ... disk vid

Scheduler

• All services are processes

7
O.S. by Er. K.S.Dhindsa © 2007
Process Control Block

• Each process has a PCB


containing every info about that process

• OS keeps a table of PCB’s, one per


process

8
O.S. by Er. K.S.Dhindsa © 2007
Process Control Block (PCB)

9
O.S. by Er. K.S.Dhindsa © 2007
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

10
O.S. by Er. K.S.Dhindsa © 2007
CPU Switch From Process to Process

11
O.S. by Er. K.S.Dhindsa © 2007
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

12
O.S. by Er. K.S.Dhindsa © 2007
QUEUEING DIAGRAM --Representation of Process Scheduling

RESOURCES
Flow of processes

Device
queues

13
O.S. by Er. K.S.Dhindsa © 2007
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
 Short-term scheduler is invoked very frequently
(milliseconds) ⇒ (must be fast)
 Long-term scheduler is invoked very infrequently
(seconds, minutes) ⇒ (may be slow)
The long-term scheduler controls the degree of
multiprogramming
14
O.S. by Er. K.S.Dhindsa © 2007
Medium Term Scheduling??

MTS ???

15
O.S. by Er. K.S.Dhindsa © 2007
Schedulers (Cont.)
• Processes can be described as either:

– I/O-bound process – spends more time


doing I/O than computations, many short CPU
bursts
– CPU-bound process – spends more time
doing computations; few very long CPU bursts

16
O.S. by Er. K.S.Dhindsa © 2007
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(occurs fast in microseconds)

• Context-switch time is overhead; the system


does no useful work while switching

• Time dependent on hardware support


17
O.S. by Er. K.S.Dhindsa © 2007
Context Switch
• Pure overhead
• So … fast, fast, fast
– typically 1 to 1000 microseconds
• Sometimes special hardware to speed
up

• How to decide when to switch contexts to


another process is process scheduling
18
O.S. by Er. K.S.Dhindsa © 2007
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
• Execution
– Parent and children execute concurrently
– Parent waits until children terminate

19
O.S. by Er. K.S.Dhindsa © 2007
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

20
O.S. by Er. K.S.Dhindsa © 2007
Client-Server Communication

• Sockets

• Remote Procedure Calls

21
O.S. by Er. K.S.Dhindsa © 2007
Sockets

• A socket is defined as an endpoint for


communication
• Concatenation of IP address and port
• The socket 161.25.19.8:1625 refers to port
1625 on host 161.25.19.8
• Communication consists between a pair of
sockets

22
O.S. by Er. K.S.Dhindsa © 2007
Socket Communication

23
O.S. by Er. K.S.Dhindsa © 2007
Remote Procedure Calls ????
• Remote procedure call (RPC) abstracts
procedure calls between processes on
networked systems
• Stubs – client-side proxy for the actual
procedure on the server
• The client-side stub locates the server and
marshalls the parameters.
• The server-side stub receives this message,
unpacks the marshalled parameters, and
peforms the procedure on the server.

24
O.S. by Er. K.S.Dhindsa © 2007
Threads
“Multithreaded Program”
• Basic unit of CPU utilization Process
• Also called Lightweight Processes (LWP) text segment
• Consists of : A B C
Program
– program counter
Counter
– register set
– stack space (Threads)
• Shares :

A stack
B stack
C stack
– code section
– data section TASKS
– OS resources A B C
(open files& signals)
data segment
25
O.S. by Er. K.S.Dhindsa © 2007
Thread Features :
 Threads can be in any of the states:
ready,blocked,running or terminated

 A thread must be in exactly in one task

 A task does nothing if there are no threads in it

 Like Processes,
Threads share CPU,and only one thread at a time is active

 A thread within a process executes sequentially & each thread


has its own stack and program counter

Thread Benefits ??
26
O.S. by Er. K.S.Dhindsa © 2007
Threads Standards

• POSIX (Pthreads)
– Common API
– Almost all Unix’s have thread library
• Solaris
– started before POSIX standard
– likely to be same as POSIX

27
O.S. by Er. K.S.Dhindsa © 2007
Levels of Threads

User Level Thread


Process A Process B
Thread

Kernel Thread

28
O.S. by Er. K.S.Dhindsa © 2007
PROCESSES

Lecture Series By :
Er. Kanwalvir Singh Dhindsa

Website ::
www.dhindsa.info

http://groups.google.com/group/os-2007

29
O.S. by Er. K.S.Dhindsa © 2007

Вам также может понравиться