Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Process Management. 2 Process Process is a program in execution; process execution must progress in sequential fashion A process includes: –program.

Similar presentations


Presentation on theme: "1 Process Management. 2 Process Process is a program in execution; process execution must progress in sequential fashion A process includes: –program."— Presentation transcript:

1 1 Process Management

2 2 Process Process is a program in execution; process execution must progress in sequential fashion A process includes: –program counter –Stack (Registers) contains temporary data such a functions parameters, return address and local variables –data section (global Variables)

3 3 Process Model In this model all the runnable software on the computer, sometimes including the operating system, is organized into a number of sequential processes or simply processes. Conceptually each process has its own virtual CPU, in reality the real CPU switches back and forth from process to process (multiprogramming)

4 (a)Multiprogramming of four programs. (b) Conceptual model of four independent, sequential processes. (c) Only one program is active at once. The Process Model

5 5 Difference between Process and Program Program is an algorithm expressed in a suitable notation where as a process is a program in execution Process is an activity of some kind. It has a program, input, output and a state. A single processor may be shared among several processes, with some scheduling algorithm being used to determine when to stop work on one process and service a different one.

6 Events which cause process creation: System initialization. Execution of a process creation system call by a running process. A user request to create a new process. Initiation of a batch job. Process Creation

7 7 Process Creation-System initialization When an OS is booted, several processes are created Foreground processes-interact with the user and perform work for them Background processes-not associated with particular users, but instead have specific function (e.g. a background process to accept incoming request for web pages hosted on a machine, waking up when the request comes)

8 8 Process Creation- by process creation system call A running process may issue system calls to create one or more new processes to help it do the job Useful when the work to be done can be formulated in terms of several related but otherwise independent interacting processes E.g. In Unix when compiling a large program, the make program invokes the C compiler to convert source file to object code and then it invokes the install program to copy the program to its destination, set ownership and permissions etc.

9 9 Process Creation- User Request, Initialization of a batch process In interactive systems, users can start a program by typing a command In case of batch processing systems, users can submit batch jobs to the system. When OS decides that it has the resources to run another job, it creates a new process and runs the next job from the input queue in it.

10 10 Process Termination Events which cause process termination: Normal exit (voluntary). Error exit (voluntary). Fatal error (involuntary). Killed by another process (involuntary).

11 11 Process Termination-Normal Exit If a process has completed it work then it performs a normal exit voluntarily. E.g. When a compiler has compiled the program given to it, the compiler executes a system call to tell the OS that it has finished the compilation

12 12 Process Termination-Error exit If a process discovers a fatal error it performs a error exit voluntarily E.g. if a user types the command to compile a program and no such file exists, the compiler simply exits

13 13 Process Termination-fatal error If an error is caused by the process due to a program bug it discovers a fatal error and terminates involuntarily E.g. Executing an illegal instruction, referencing nonexistent memory or dividing by zero

14 14 Process Termination-Killed by another process If one process executes a system call telling the operating System to kill another process (the killing process must have the authorization to kill the process) In some systems, when a process terminates, either voluntarily or involuntarily, all process it has created will be immediately killed

15 15 Process Hierarchies Parent creates a child process, child processes can create its own process Unix forms a hierarchy –Unix calls this a "process group” Windows has no concept of process hierarchy –all processes are created equal

16 A process can be in running, blocked, or ready state. Transitions between these states are as shown. Process States

17 17 Process States When a process blocks, it does so because logically it can continue, typically because it is waiting for input that is not yet available It may be ready and able to run to be stopped because the OS has decided to allocate the CPU to another process for a while

18 18 Implementation of processes To implement the process model,the OS maintains a table called the process table (an array of structures), with one entry per process (also called Process control Blocks) This entry contains information about –the process’ state, –its program counter, –stack pointer, –memory allocation, –the status of its open files, –its accounting and scheduling information, –alarms and other signals That must be saved when process switches from running to ready state so that it can be restarted later

19 The lowest layer of a process-structured operating system handles interrupts and scheduling. Above that layer are sequential processes. Implementation of Processes (1)

20 20 Implementation of Processes (2)

21 Some of the fields of a typical process table entry. Implementation of Processes (3)

22 Skeleton of what the lowest level of the operating system does when an interrupt occurs. Implementation of Processes (4)

23 23 Process Control Block (PCB) Information associated with each process Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

24 24 Process Control Block (PCB)

25 25 CPU Switch From Process to Process

26 26 Process Scheduling The objective of multiprogramming is to have some process running at all times to maximize CPU utilization. The objective of time sharing is to switch the CPU among processes so frequently that users can interact with each program while it is running. To meet these objectives, the process scheduler selects an available process from a set of available process, for program execution on the CPU

27 27 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, generally stored as a linked list. A ready-queue header contains the pointers to first and last PCB in the list. Each PCB includes a pointer that points to the next PCB in the ready queue Device queues – set of processes waiting for an I/O device. Each device has its own device queue Processes switches among the various queues

28 28 Ready Queue And Various I/O Device Queues

29 29 Process Scheduling-Queuing Common representation of process scheduling is queuing diagram. Each rectangular box represents a queue (ready & set of device queues). Circles represent resources that serve the queue and arrow show the flow of processes in the system. A new process is put in a ready queue. It waits there until it is selected for execution or s dispatched Once the process is allocated to CPU and is executing,these events could happen –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 its termination. – Due to an interrupt the process may be removed form CPU forcefully and put back in ready queue

30 30 Representation of Process Scheduling

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

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

33 33 Addition of Medium Term Scheduling

34 34 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 via a task known as Context Switch Context of a process represented in the PCB Context-switch time is overhead; the system does no useful work while switching Time dependent on hardware support

35 35  The term thread is shorthand for "thread of control." A thread is the path taken by a program while running, the steps performed, and the order in which the steps are performed. A thread runs code from its starting location in an ordered, predefined sequence for a given set of inputs.  Like a process, except that some state is shared  Threads have their own registers and stack frames  Threads share memory  Tradeoffs: better performance vs. programming complexity + less protection  Switching to another thread: save registers, find the right stack frame, load registers, run thread  Typically used to service asynchronous events Threads

36 36 Single and Multithreaded Processes

37 37 Thread models User threads model, all program threads share the same process thread. The scheduling policy allows only one thread to be actively running in the process at a time. The operating system kernel is only aware of a single task in the process. Kernel threads model, kernel threads are separate tasks that are associated with a process. Uses a pre-emptive scheduling policy in which the operating system decides which thread is eligible to share the processor. One-to-one mapping between program threads and process threads. OS/400 supports a kernel thread model. MxN thread model. Each process has M user threads that share N kernel threads. The user threads are scheduled on top of the kernel threads. The system allocates resources only to the more "expensive" kernel threads.

38 38 Inter-Process Communication Process executing concurrently in the Operating Systems may be either independent processes or cooperating processes An independent process cannot affect or be affected by the other processes executing in the system (Any process that do not share data with any other process) A Cooperating process will affect or be affected by the other processes executing in the system (Any process that share data with any other process)

39 39 Reasons for Cooperating processes –Information sharing –Computation speedup –Modularity –Convenience (user may work on same task at the same time) Cooperating processes need inter-process communication (IPC) Two models of IPC –Shared memory –Message passing

40 40 Communications Models Message Passing Shared Memory

41 41 Shared Memory Systems Communicating processes must establish a region of shared memory. A shared memory region resides in the address space of the process creating the shared memory segment.Other processes that wish to communicate using this shared memory segment must attach it to their memory space. Normally the OS tries to prevent the processes from accessing other process address space, but this type of IPC requires processes to agree to remove this restriction. They exchange information by reading and writing in this shared area. The form of data and the location must be determined by the processes and are not under OS’s control

42 42 Interprocess Communication – Message Passing Mechanism for processes to communicate and to synchronize their actions Message system – processes communicate with each other without resorting to shared variables IPC facility provides two operations: –send(message) – message size fixed or variable –receive(message) If P and Q wish to communicate, they need to: –establish a communication link between them –exchange messages via send/receive Implementation of communication link –physical (e.g., shared memory, hardware bus) –logical (e.g., logical properties)

43 43 Direct Communication Processes must name each other explicitly: –send (P, message) – send a message to process P –receive(Q, message) – receive a message from process Q Properties of communication link –Links are established automatically –A link is associated with exactly one pair of communicating processes –Between each pair there exists exactly one link –The link may be unidirectional, but is usually bi- directional

44 44 Indirect Communication Messages are directed and received from mailboxes (also referred to as ports) –Each mailbox has a unique id –Processes can communicate only if they share a mailbox Properties of communication link –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 links –Link may be unidirectional or bi-directional

45 45 Indirect Communication Operations –create a new mailbox –send and receive messages through mailbox –destroy a mailbox Primitives are defined as: send(A, message) – send a message to mailbox A receive(A, message) – receive a message from mailbox A

46 46 Indirect Communication Mailbox sharing –P 1, P 2, and P 3 share mailbox A –P 1, sends; P 2 and P 3 receive –Who gets the message? 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.

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

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


Download ppt "1 Process Management. 2 Process Process is a program in execution; process execution must progress in sequential fashion A process includes: –program."

Similar presentations


Ads by Google