Академический Документы
Профессиональный Документы
Культура Документы
Outline
Output Device Processor
Input Device
Idea
Program Result
Idea
Program
Result
SPRING 2011 - 102
Program
Abstract Machine
Physical Machine
Result
Idea
Program
Abstract Machine
Result
Process: A sequential program in execution Resource: Any abstract resource that a process can request, and which may can cause the process to be blocked if the resource is unavailable.
A program in execution An instance of a program running on a computer The entity that can be assigned to and executed on a processor A unit of activity characterized by the execution of a sequence of instructions, a current state, and an associated set of system instructions.
Algorithm
Status Stack
R U N
Source Program
Binary Program
Data
Other Resources
Process
SPRING 2011 - 102
10
11
Process state
Program counter
CPU registers CPU scheduling information Memory-management information Accounting information
12
Consider three processes being executed All are in memory (plus the dispatcher) Lets ignore virtual memory for this.
13
14
Timeout I/O
15
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 switching
Context-switch time is overhead; the system does no useful work while switching It is the job of Dispatcher. The time it takes for a dispatcher to stop one process and start another is known as dispatch latency. Interrupt, Trap and signal triggers a process switch.
16
17
18
Running Not-running
19
Etc processes moved by the dispatcher of the OS to the CPU then back to the queue until the task is competed
20
New Running
Exit
Not Running
new: The process is being created running: Instructions are being executed Not Running
Not Running
Ready
waiting: The process is waiting for some event ready: The process is waiting to be run
Blocked
21
Job accepted
Time out
Event happened
22
Limitations
If all processes in the queue are always ready to execute only then the above queuing discipline will work. But it may also be possible that some processes in the queue are ready to execute, while some are waiting for an I/O operation to complete. So the dispatcher has to scan the list of processes looking for the process that is not blocked and is there in the queue for the longest SPRING 2011 - 102
23
In the simplest solution, model require an queue for the blocked processes. But when an event occurs the dispatcher would have to cycle through the entire queue to see which process is waiting for the event. This can cause huge overhead when their may be 100s or 1000s of processes
SPRING 2011 - 102
24
Job Queue
Ready queue set of all processes residing in main memory, ready and waiting to execute
SPRING 2011 - 102
25
Job Queue
26
27
A process switch may occur any time that the OS has gained control from the currently running process. Possible events giving OS control are: Mechanism Interrupt Cause External to the execution of the current instruction Use Reaction to an asynchronous external event
Associated with the execution of Handling of an error or an the current instruction exception condition Explicit request Call to an operating system function
28
Update the process control block of the process that is currently in the Running state
Move process control block to appropriate queue ready; blocked; ready/suspend
Select another process for execution Update the process control block of the process selected Restore context of the selected process
SPRING 2011 - 102
29
30
A process migrates between various scheduling queues throughout its life cycle. OS must select processes from these queues in some predefined fashion. This selection is done by an appropriate scheduler
Objective of Multiprogramming
Process Scheduler
SPRING 2011 - 102
31
Job Queue
Short-term scheduler (or CPU scheduler) selects which process should be executed next and allocates CPU
SPRING 2011 - 102
32
Long-term scheduler (or job scheduler) selects processes from the job pool (processes spooled on hard disk) to be brought into the ready queue (inside main memory).
Long-term scheduler is invoked very infrequently (seconds, minutes) (may be slow) The long-term scheduler controls the degree of multiprogramming
33
CPU slice of the current process finishes Current process needs to wait for an event Clock interrupt I/O interrupt System call Signal
SPRING 2011 - 102
34
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
If the degree of multi programming is stable, then the average rate of process creation must be equal to the average departure rate of process leaving the system
The degree of multiprogramming describes the maximum number of processes that a singleprocessor system can accommodate efficiently SPRING 2011 - 102
35
Also known as swapper It can suspend one process by putting it in the suspended states and transferring it to disk. This is called a swap-out operation. Now the main memory has space to bring in a new process. The swapped out process can be swapped-in later on Swapping decision is based on several factors Arrival of a higher priority process but no memory available To improve process mix. Requiring memory to be freed up because memory requirement of a process cannot be met.
SPRING 2011 - 102
36
37
38
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 parents resources
Execution
Parent and children execute concurrently Parent waits until children terminate
SPRING 2011 - 102
39
Address space
UNIX examples
fork system call creates new process exec system call used after a fork to replace the process memory space with a new program
40
41
Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting , Some operating system do not allow child to continue if its parent terminates
All children terminated
- cascading termination
42
43
Process
(Executing Concurrently)
Cooperating
It can affect OR Can be affected by any other process.
Independent
It cannot affect OR Can not be affected by any other process.
44
Independent
process is a
Cooperating
process is a
process that cannot affect or cannot be affected by the execution of another process. A process that does not share data with another process is independent
process that can affect or can be affected by the execution of another process. A process that share data with other process is cooperating process.
45
Message passing
Inter Process
46
IPC is a mechanism for processes to communicate and to synchronize their actions. There are two fundamental models of IPC:
Shared Memory A region of memory that is shared by cooperating processes is established. Processes can then exchange information by reading and writing data to the shared region. Messaging system Communication takes place by means of messages exchanged between the cooperating processes. Processes communicate with each other without resorting to shared variables.
SPRING 2011 - 102
47
Process 1 Process 2
Process - 1
Shared
Process - 2
Kernel
Kernel
Message Passing
Shared Memory
48
Useful for Exchanging smaller amount of data. Much easier to implement than shared Memory in inter-computer communications. Implemented by using System calls Requires More time (Kernel Intervention)
Shared Memory allows max Speed. Generally convenient for IPC, as done at memory speed. Faster in case of one computer. Kernel intervention is only required t beginning.
Message Passing
Shared Memory
SPRING 2011 - 102
49
50
Lets take an Example of Producer Consumer Model. Producer Produces information which is consumed by Consumer.
Producer Compiler
Consumer
Assembly Code
Assembler Producer
Object Code
Loader Consumer
51
To allow producer and consumer run concurrently we must have a buffer that can be filled by the producer and emptied by the consumer. Buffer can be bounded or unbounded.
52
Message passing provides a mechanism to allow processes to communicate and to synchronize their actions without sharing the same address space. It is particularly useful in a distributed environment. If P and Q wish to communicate, they need to:
53
54
send (P, message) send a message to process P receive(Q, message) receive a message from process Q
A Link is established automatically. A link is associated with exactly one pair of communicating processes. S 2011 - 102 Between each pair there exists exactly one link
PRING
55
Link established only if processes share a common mailbox. A link may be associated with many processes Each pair of processes may share several communication S 2011 - 102 links.
PRING
Operations create a new mailbox send and receive messages through mailbox destroy a mailbox
Mailbox sharing P1, P2, and P3 share mailbox A. P1, sends; P2 and P3 receive. Who gets the message?
16 MARCH 2011
Solutions
Allow a link to be associated with at most two processes. Allow only one process at a time to execute a receive operation. Allow the system to select arbitrarily the receiver. Sender is notified who the receiver was.
16 MARCH 2011
58
Blocking send has the sender block until the message is received Blocking receive has the receiver block until a message is available
Non-blocking send has the sender send the message and continue Non-blocking receive has the receiver receive a valid message or null
SPRING 2011 - 102
59