Top Banner
Operating Systems Part III: Process Management (Process States and Transitions)
30

Operating Systems Part III: Process Management (Process States and Transitions)

Jan 01, 2016

Download

Documents

Brice Martin
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Operating Systems Part III: Process Management (Process States and Transitions)

Operating Systems

Part III: Process Management (Process States and Transitions)

Page 2: Operating Systems Part III: Process Management (Process States and Transitions)

Process Definition

Definition (informal): A process is a program in execution

Referred to as a job in batch systems and user program / task in time-shared systems

More broadly: all CPU activities (includes user programs, internal O/S activities, etc.)

Page 3: Operating Systems Part III: Process Management (Process States and Transitions)

Process States

Processes are executed sequentially Process States:

– New: process is being created– Running: instructions are being executed– Waiting: waiting for an event (i.e. I/O completion)– Ready: waiting to be assigned to a processor– Terminated: process has finished execution

Page 4: Operating Systems Part III: Process Management (Process States and Transitions)

Process States

new

waiting

running

ready

terminated

admitted

interrupt

exit

scheduler dispatch

I/O or event waitI/O or event completion

Page 5: Operating Systems Part III: Process Management (Process States and Transitions)

Process Control Block

Each process is represented by a process control block (PCB)

Information contained in PCB:– Process state– Program counter: address of next instruction– CPU registers: accumulators, index registers, stack

pointers -- must be saved when interrupt occurs

Page 6: Operating Systems Part III: Process Management (Process States and Transitions)

Process Control Block

Information in PCB (continued)– CPU scheduling information - process priority &

scheduling parameters– Memory-management information - page tables, etc.– Accounting information - amount of CPU USED– I/O status information - list of I/O devices allocated

to this process, list of open files, etc.

Page 7: Operating Systems Part III: Process Management (Process States and Transitions)

Process Scheduling

Processes are put in a job queue (consists of all processes)

Processes residing in main memory (ready and waiting) are kept in ready queue

Uni-processor (only one running process at a time); multiprocessor (# of processes running depend on # of processors)

Page 8: Operating Systems Part III: Process Management (Process States and Transitions)

Process Scheduling

Long-term scheduler (a.k.a. job scheduler) - selects processes from mass storage device and loads into main memory for execution

Short-term scheduler (a.k.a. CPU scheduler) - selects from ready to execute processes and allocates CPU to one of them

Page 9: Operating Systems Part III: Process Management (Process States and Transitions)

Process Scheduling

CPU-bound process - spends more time doing computation

I/O-bound process - spends more time doing I/O

Medium-term scheduler - removes some processes in main memory and then later reintroduced to continue execution --> also called swapping

Page 10: Operating Systems Part III: Process Management (Process States and Transitions)

Process Scheduling

Job Queue(New)

Secondary Memory

Main Memory

Ready Queue(Ready) CPU

(Running)

long - term / job scheduler short -

term / CPU scheduler

I/O Queue(Waiting)

Portion of Virtual Memory

medium - term scheduler / swapper

I/O

I/O complete

I/O request

interruptExit

(Terminated)

Page 11: Operating Systems Part III: Process Management (Process States and Transitions)

Process Scheduling

Context switch – CPU switching from one process to another– Purely overhead because system does no useful

work– Value of registers must be copied to PCB– Speed ranges vary from machine to machine (but

typically 1 to 1000 microseconds)

Page 12: Operating Systems Part III: Process Management (Process States and Transitions)

Operation in Processes

Process creation– Created via a create-process system call– Creating process is the parent process and the new

process is the child process– Forms a tree of processes

Page 13: Operating Systems Part III: Process Management (Process States and Transitions)

Operation in Processes

Process creation (continued)– Two possibilities (execution)

Parent continues to run concurrently w/ children Parent waits until some/all children have finished

– Two possibilities (address space) Child has duplicate of parent address space Child has program loaded into parent address space

Page 14: Operating Systems Part III: Process Management (Process States and Transitions)

Operation in Processes

Process creation (continued)– In Unix, new process is created using the fork

system call Parent continues execution Copy of address space is created

– Also in Unix, execve is similar to fork except Parent “dies” Memory space replaced by child

Page 15: Operating Systems Part III: Process Management (Process States and Transitions)

Operation in Processes

Process termination– Normally terminates w/ exit system call (Unix)– All resources are deallocated by O/S– Other circumstances

Parent terminates child (i.e. abort)– Child exceeded usage of resources– Child is no longer required– Parent is exiting, O/S does not allow child to exist without

parent Process killed by other processes (user’s own)

Page 16: Operating Systems Part III: Process Management (Process States and Transitions)

Cooperating Processes

Independent process - cannot affect or be affected by other processes (does not share any data)

Dependent process - if it can affect or be affected by other processes (shares data with other processes)

Page 17: Operating Systems Part III: Process Management (Process States and Transitions)

Cooperating Processes

Reasons for sharing data w/ other processes– Information sharing– Computation speedup - break complex task into

subtasks– Modularity - divide a system into separate

processes– Convenience - work on many tasks at the same time

(editing/printing/compiling)

Page 18: Operating Systems Part III: Process Management (Process States and Transitions)

Cooperating Processes

An illustration– Producer-consumer problem: producer produces

information for the consumer to consume (i.e. print program and printer device)

– Unbounded-buffer -> no limit on size of buffer but consumer has to wait for new items

– Bounded-buffer -> fixed buffer (consumer waits if buffer is empty, producer if full)

Page 19: Operating Systems Part III: Process Management (Process States and Transitions)

Threads

Allows sharing of resources among peers Also called a lightweight process (LWP) Has a program counter, register set, and stack

space Shares with peer threads its code section, data

section, O/S resources (collectively known as a task)

Page 20: Operating Systems Part III: Process Management (Process States and Transitions)

Threads

Traditional task (heavyweight process) has exactly one thread

Threads makes CPU switching among peers less expensive than among heavyweight processes (no memory mgt.)

Page 21: Operating Systems Part III: Process Management (Process States and Transitions)

Threads

Similar to processes since a thread– has states (ready, running, blocked, terminated)– can create child threads– shares CPU

Page 22: Operating Systems Part III: Process Management (Process States and Transitions)

Threads

Unlike a process, threads– are not independent of each other– can access every address in the task– have no protection from other threads since threads

are meant to assist and not be hostile to one another

Threads are gaining ground because they execute more efficiently

Page 23: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Cooperating processes communicate through a shared-memory environment

Another means is through an interprocess-communication (IPC) facility– Achieved through a messaging system

Function of message system is to allow process communication without resorting to shared variables

Page 24: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

IPC provides at least two basic functions:– send(message)– receive(message)

A communication link must exist between two or more processes

Unidirectional link – can either send or receive but NOT BOTH and each link has at least one receiver process connected to it

Page 25: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Processes refer to each other through names Name referencing is used in direct and indirect

communication Direct communication

– send(process_name,message)– receive(process_name,message)– The link is exactly between two processes and

usually bi-directional (sometimes unidirectional)

Page 26: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Direct communication (continued)– Example:

Producer-consumer problem: when producer finishes, it sends to the consumer

– Symmetric – sender and receiver indicate process name

– Asymmetric – only the sender specifies the process name; receiver can receive message from any process

– Disadvantage: limited modularity (e.g. when process changes name)

Page 27: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Indirect communication– Messages sent through a mailbox

send(mailbox_name,message) receive(mailbox_name,message)

– Link is established between processes ONLY through a shared mailbox

– Mailbox may be owned by either the process or the system– Mailboxes owned by the process are destroyed when process

terminates

Page 28: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Buffering– Link capacity determines number of messages that

can reside in it temporarily– Zero capacity

No messages can wait in buffer Sender waits until recipient receives Must be synchronized to transfer a message (rendezvous)

Page 29: Operating Systems Part III: Process Management (Process States and Transitions)

Interprocess Communication

Buffering (continued)– Bounded capacity

With finite length n Sender waits if buffer is full

– Unbounded capacity Sender never delays

Page 30: Operating Systems Part III: Process Management (Process States and Transitions)

Communication in Client-Server Systems

Socket– An endpoint for communication– A link consists of two sockets

RPC (Remote Procedure Call)– Allows a local process to invoke a procedure on a

remote host as if accessing a local procedure

RMI (Remote Method Invocation)– The Java implementation of RPC