Presentation is loading. Please wait.

Presentation is loading. Please wait.

Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.

Similar presentations


Presentation on theme: "Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems."— Presentation transcript:

1 Processes

2 Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems

3 What the OS is going to do for the process? Creating and removing (destroying) process Controlling the progress of processes Acting on interrupts and arithmetic errors. Resource allocation among processes Inter process communication

4 Process Concept An operating system executes a variety of programs batch systems - jobs time-shared systems - user programs or tasks Process - a program in execution process execution proceeds in a sequential fashion Program is a passive entity, process is an active entity. A process contains program counter stack data section

5 Process in Memory

6 Process State A process may be in 1 of the following 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.

7 Process State

8 Process Control Block (PCB) Information associated with each process Process State e.g. new, ready, running etc Program Counter address of next instruction to be executed CPU Registers general purpose registers, stack pointer etc. CPU-Scheduling Information process priority, pointer Memory –management information base/limit information Accounting information CPU time used, process number.. I/O status information list of I/O devices allocated

9 Process Control Block (PCB)

10 10 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.

11 CPU Switch From Process to Process

12 Process Scheduling Maximize CPU use, quickly switch processes onto CPU for time sharing Process scheduler selects among available processes for next execution on CPU

13 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

14 Ready Queue And Various I/O Device Queues

15 Representation of Process Scheduling

16 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

17 Schedulers (Cont.) 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 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

18 Addition of Medium Term Scheduling

19 Interprocess Communication Processes within a system may be independent or cooperating Cooperating processes need interprocess communication (IPC) Two models of IPC – Shared memory – Message passing

20 Communications Models

21 Cooperating Processes Advantages of process cooperation – Information sharing – Computation speed-up – Modularity – Convenience

22 Producer-Consumer Problem Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process – unbounded-buffer places no practical limit on the size of the buffer – bounded-buffer assumes that there is a fixed buffer size

23 Bounded-Buffer – Shared-Memory Solution Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0;

24 Bounded-Buffer – Producer while (true) { /* Produce an item */ while (((in = (in + 1) % BUFFER SIZE count) == out) ; /* do nothing -- no free buffers */ buffer[in] = item; in = (in + 1) % BUFFER SIZE; }

25 Bounded Buffer – Consumer while (true) { while (in == out) ; // do nothing -- nothing to consume // remove an item from the buffer item = buffer[out]; out = (out + 1) % BUFFER SIZE; return item; }

26 Message passing systems For distributed environment Message passing implemented using system calls, (kernel intervention required each time) Message passing is easy to implement Message passing is useful for exchanging smaller amount of data.

27 Cooperating Processes via Message Passing IPC facility provides two operations. send(message) - message size can be fixed or variable receive(message) If processes P and Q wish to communicate, they need to: – establish a communication link between them – exchange messages via send/receive Fixed vs. Variable size message

28 Direct communication Each process that wants to communicate must explicitly name the recipient or sender of the communication. send(P, msg) - send a message to process P receive(Q, msg) - receive a message from process Q

29 Indirect communication – Indirect communication receive/send(A, msg) A: is the mailbox

30 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 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

31 Buffering Queue of messages attached to the link; implemented in one of three ways 1.Zero capacity – 0 messages Sender must wait for receiver. 2.Bounded capacity – finite length of n messages Sender must wait if link full 3.Unbounded capacity – infinite length Sender never waits

32 IPC using “pipes” Ordinary pipes: data is written by a process on one end (write-end) and read by another process at other end (read-end). Unidirectional Pipe is treated as a special type of file, can be accessed by read() or write() system calls. Ordinary pipe can be used within a process only (parent and child processes)

33

34


Download ppt "Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems."

Similar presentations


Ads by Google