Presentation is loading. Please wait.

Presentation is loading. Please wait.

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.

Similar presentations


Presentation on theme: "Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept."— Presentation transcript:

1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept

2 3.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 3: Process-Concept Process Concept Process Scheduling Interprocess Communication

3 3.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Objectives To introduce the notion of a process -- a program in execution, which forms the basis of all computation To describe the various features of processes, including scheduling, creation and termination, and communication

4 3.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition

5 3.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Concept An operating system executes a variety of programs: In Batch system – jobs In Time-shared systems – user programs or tasks Textbook uses the terms job and process almost interchangeably (job = process) Process – is a program loaded into memory and executing. System consists of a collection of processes: Operating system processes executing system code User processes executing user code. Process execution must progress in sequential fashion

6 3.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition The Process Process includes: Text section : which is program code Stack- which contains temporary data (such as function parameters, return addresses, and local variables) Data section: which contains global variables. Program counter: the value of the program counter & contents of the processor’s registers. Heap (some times): which is memory that is dynamically allocated during process run time.

7 3.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process VS Program What is the difference between a process and program?? A program by itself is not a process A program is a passive entity, such as a file containing a list of instructions stored on disk (executable file). A process is an active entity, with a program counter specifying the next instruction to execute and a set of associated resources. A program becomes a process when an executable file is loaded into memory.

8 3.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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 (e.g. An I/O completion). Ready: the process is waiting to be assigned to a processor Terminated: the process has finished execution Only one process can be running on any processor at any instant. Many processes may be ready and waiting.

9 3.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Diagram of Process State

10 3.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Control Block (PCB) Each process is represented in the operating system by a process control block (PCB) PCB contains many information including :  Process state  Program counter  CPU registers  CPU scheduling information – e.g. a process priority  Memory-management information  Accounting information: – e.g. when the process was last run, how much CPU time it has used  I/O status information – It includes the list of I/O devices allocated to the process, a list of open files….etc. Values of program counter & CPU registers must be saved when an interrupt occurs to allow the process to be continued correctly afterward

11 3.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Control Block (PCB)

12 3.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition CPU Switch From Process to Process

13 3.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition

14 3.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Scheduling Multiprogramming aims to have some process running at all times to maximize CPU utilization. Time sharing aims to switch the CPU among processes so frequently user interact with each program while it is running. Process scheduler selects an process (from a set of several available processes) for execution on the CPU.

15 3.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition 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 This queue is generally stored as a linked list. Device queues – set of processes waiting for an I/O device Each device has its own device queue

16 3.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process Scheduling Queues (cont.) Processes migrate among the various queues: A new process is initially put in the ready queue. It waits there until it is selected for execution. Once the process is allocated the CPU and is executing, one of several events could occur:  The process could issue an I/O request and then be placed in an I/O queue.  The process could create a new sub-process and wait for the sub- process’s termination.  The process could be removed forcibly from the CPU as a result of an interrupt, and be put back in the ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated.

17 3.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Representation of Process Scheduling Queuing diagram

18 3.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Schedulers The operating system must select processes scheduling these queues. The selection process is carried out by the appropriate scheduler. Long-term scheduler (or job scheduler) – selects which processes should be brought from mass-storage into RAM (to the ready queue ) Short-term scheduler (or CPU scheduler) – selects which process (from ready queue) 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

19 3.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Schedulers (Cont) Processes can be described as either: I/O-bound process – spends more time doing I/O than computations, many short CPU intervals CPU-bound process – spends more time doing computations; few very long CPU intervals. The long-term scheduler must select a good process mix of I/O- bound and CPU-bound processes to improve total performance. If all processes are I/O bound >>> the ready queue will almost always be empty, and the short-term scheduler will have little to do….(minimize CPU utilization) If all processes are CPU bound >>> the I/O waiting queue will almost always be empty, devices will go unused….(minimize devices utilization)

20 3.20 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Medium Term Scheduling Medium Term Scheduling idea is : Sometimes it can be advantageous to remove processes from RAM …….(swap out) Later, the process can be reintroduced into RAM …….(swap in), and its execution can be continued where it left off. This scheme is called swapping. The process is swapped out, and is later swapped in, by the medium-term scheduler.  Swapping may be necessary to improve the process mix or because a change in memory requirements has exceeded available memory, requiring memory to be freed up.

21 3.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Addition of Medium Term Scheduling

22 3.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition

23 3.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Interprocess Communication Processes within a system may be independent or cooperating – Independent processes » Cannot affect or be affected by the execution of another process. – Cooperating processes » Can affect or be affected by the execution of another process Reasons (/advantages) for cooperating processes: Information sharing : (e.g. shared file) Computation speedup:  To make a particular task run faster, we must break it into subtasks, each of which will be executing in parallel with the others.  This can be achieved only if the computer has multiple processing elements (e.g. CPUs). Modularity:  We may want to construct the system in a modular fashion (i.e. dividing the system functions into separate processes) Convenience  An individual user may work on many tasks at the same time.

24 3.24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Interprocess Communication (Cont.) Cooperating processes need interprocess communication (IPC) IPC: mechanism that will allow cooperating processes to exchange data and information. Two 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. Message passing  Communication takes place by means of messages exchanged between the cooperating processes..

25 3.25 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Communications Models Message passing model Shared memory model

26 3.26 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Message passing VS Shared memory Both models are common in operating systems, and many systems implement both. Message passing: Useful for exchanging smaller amounts of data, because no conflicts need be avoided. Easier to implement than shared memory. Shared memory Shared memory is faster than message passing …..Because message passing systems requires more system calls (interrupts).

27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, End of Chapter 3

28 3.28 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Some Helpful Notes Some Terminologies : Batch system :  System which Jobs are set up so they can be run to completion without human (/user) interaction.  This operating environment is termed as "batch processing" because the input data are collected into batches or sets of records and each batch is processed as a unit.  A program takes a set of data files as input, processes the data, and produces a set of output data files.  An example of a batch system is when a computer system processes telephone bills to a number of customers and then sends them out all at once rather than individually. Program counter: is a register in a computer processor that contains the address (location) of the next instruction to be executed Heap : is a partially sorted binary tree….(data structure)

29 3.29 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Some Helpful Notes Modular programming is the process of subdividing a computer program into separate sub-programs.  Each sub-program accomplishes one function and contains all needed source code and variables.  Modular programming is a solution to the problem of very large programs that are difficult to debug and maintain.


Download ppt "Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept."

Similar presentations


Ads by Google