Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Module 3: Processes Reading: Chapter 4.1-4.4 Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.

Similar presentations


Presentation on theme: "1 Module 3: Processes Reading: Chapter 4.1-4.4 Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3."— Presentation transcript:

1 1 Module 3: Processes Reading: Chapter 4.1-4.4 Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3

2 2 Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems

3 3 What is a process Process – a program in execution Process: –Code (“text section”) –CPU Registers (including PC, SP) –Process Stack (temporary data: e.g. method parameters, return addresses, local variables) –Data Section (global variables) Key concept: processes are separated: no process can directly affect the state of another process.

4 4 Examples of Processes When you execute a program you have just compiled, the OS generates a process to run the program. Your WWW browser is a process.

5 5 Process vs. Program Program: static Process: dynamic Example: –A user opens two browser windows: same program, different processes.

6 6 Uniprogramming vs Multiprogramming Uniprogramming –Only one process exists at any point –Makes designing OS easier –User can’t do two things at once (MS- DOS) Multiprogramming –Multiple processes exist (only one runs at a time) –Requires protection, scheduling, etc

7 7 Multiprogramming introduces the resource sharing problem: –which processes get to use the resources and when? One crucial resource: CPU. Preemptive multitasking –OS runs one process for a while, then takes the CPU away from that process and lets another process run. Must save and restore process state. Key issue: fairness.

8 8 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 process. –terminated: The process has finished execution.

9 9 Diagram of Process State

10 10 Process Control Block (PCB) Information associated with each process. Process state Program counter CPU registers CPU scheduling information (priority, pointers to scheduling queues, etc..) Memory-management information (base & limit registers; page table;..) Accounting information I/O status information (list of open files, allocated I/O devices,…)

11 11 Process Control Block (PCB)

12 12 CPU Switch From Process to Process

13 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. Process migration between the various queues.

14 14 Ready Queue And Various I/O Device Queues

15 15 Representation of Process Scheduling: Queueing Diagram

16 16 Schedulers 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.

17 17 Context Switch Switch from running one process to running another process Solution: save and restore hardware state on a context switch. Save the state in the Process Control Block (PCB) –Program counter –Registers –Process ID –Process State –List of open files

18 18 Context Switch (continued) Context-switch time is overhead; the system does no useful work while switching. Time dependent on hardware support.

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

20 20 Process Creation (Cont.) Address space –Child duplicate of parent. –Child has a program loaded into it. 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.

21 21 Processes Tree on a UNIX System

22 22 Process Termination Conditions which terminate processes 1.Normal exit (voluntary) 2.Error exit (voluntary) 3.Fatal error (involuntary) 4.Killed by another process (involuntary)

23 23 Process Termination (cont.) Process executes last statement and asks the operating system to delete it (uses exit system call). –Output data from child to parent (via wait system call). –Process’ resources are deallocated by OS. Parent may terminate execution of children processes (uses abort system call) because: 1.Child has exceeded allocated resources. 2.Task assigned to child is no longer required. 3.Parent is exiting.  Operating system does not allow child to continue if its parent terminates.  Cascading termination.

24 24 Cooperating Processes Independent process cannot affect or be affected by the execution of another process. Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation –Information sharing –Computation speed-up –Modularity –Convenience

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

26 26 Bounded-Buffer – Shared- Memory Solution Shared data #define BUFFER_SIZE 10 typedef struct {... } item; item buffer[BUFFER_SIZE]; int in = 0; int out = 0; Solution is correct, but can only use BUFFER_SIZE-1 elements

27 27 Bounded-Buffer – Producer Process item nextProduced; while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; }

28 28 Bounded-Buffer – Consumer Process item nextConsumed; while (1) { while (in == out) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; }


Download ppt "1 Module 3: Processes Reading: Chapter 4.1-4.4 Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3."

Similar presentations


Ads by Google