Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Chapter 4: Processes Process Concept Process Scheduling Operations on Processes Cooperating Processes Interprocess Communication Communication in Client-Server Systems Operating System Concepts 4.1 Silberschatz, Galvin and Gagne 2002 Process Concept Process – a program in execution; process execution must progress in sequential fashion. A process includes: program counter:- specifying next instruction to execute & set associated resources. Stack :- to store function parameter, return address & local variable data section :- global variable Sometimes heap :- memory allocated at runtime Operating System Concepts 4.2 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.3 Silberschatz, Galvin and Gagne 2002 Diagram of Process State Operating System Concepts 4.4 Silberschatz, Galvin and Gagne 2002 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 Operating System Concepts 4.5 Silberschatz, Galvin and Gagne 2002 Process Control Block (PCB) Operating System Concepts 4.6 Silberschatz, Galvin and Gagne 2002 CPU Switch From Process to Process Operating System Concepts 4.7 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.8 Silberschatz, Galvin and Gagne 2002 Ready Queue And Various I/O Device Queues Operating System Concepts 4.9 Silberschatz, Galvin and Gagne 2002 Representation of Process Scheduling Operating System Concepts 4.10 Silberschatz, Galvin and Gagne 2002 Schedulers Process migrates among the various scheduling queue throughout its lifetime. Selection process is carried out by the appropriate scheduler. Long-term scheduler (or job scheduler) – selects which processes from job pool and load them into memory (ready queue). Short-term scheduler (or CPU scheduler) – selects which process that are ready to execute and allocates CPU to one of them. Operating System Concepts 4.11 Silberschatz, Galvin and Gagne 2002 Addition of Medium Term Scheduling •Time sharing system introduce intermediate level of scheduling called medium term scheduling • Process is swapped out and later it swapped in by this scheduler Operating System Concepts 4.12 Silberschatz, Galvin and Gagne 2002 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. LTS select a good process mix of I/O bound and CPU bound process. 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. Operating System Concepts 4.13 Silberschatz, Galvin and Gagne 2002 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 a pure overhead; the system does no useful work while switching. Time dependent on hardware support. Operating System Concepts 4.14 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.15 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.16 Silberschatz, Galvin and Gagne 2002 Process Creation Operating System Concepts 4.17 Silberschatz, Galvin and Gagne 2002 C Program Forking Separate Process int main() { pid_t pid; /* fork another process */ pid = fork(); if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); } else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0); } } Operating System Concepts Silberschatz, Galvin and Gagne 2002 4.18 Processes Tree on a UNIX System Operating System Concepts 4.19 Silberschatz, Galvin and Gagne 2002 A tree of processes on a typical Solaris Operating System Concepts 4.20 Silberschatz, Galvin and Gagne 2002 Process Termination Process executes last statement and asks the operating system to decide it (exit). Output data from child to parent (via wait). Process’ resources are deallocated by operating system. Parent may terminate execution of children processes (abort). Child has exceeded allocated resources. Task assigned to child is no longer required. Parent is exiting. Operating system does not allow child to continue if its parent terminates. Cascading termination. Operating System Concepts 4.21 Silberschatz, Galvin and Gagne 2002 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 Operating System Concepts 4.22 Silberschatz, Galvin and Gagne 2002 Shared-Memory System Producer consumer problem, producer process produces information that is consumed by a consumer process. Eg. Client Server Paradigm, program execution process Solution is shared memory. Producer and consumer must be synchronized, so that consumer does not try to consume item that has not yet been produce. Two types of buffer can be used unbounded-buffer places no practical limit on the size of the buffer. bounded-buffer assumes that there is a fixed buffer size. Operating System Concepts 4.23 Silberschatz, Galvin and Gagne 2002 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 Operating System Concepts 4.24 Silberschatz, Galvin and Gagne 2002 Bounded-Buffer – Producer Process item nextProduced; while (1) { while (((in + 1) % BUFFER_SIZE) == out) ; /* do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; } Operating System Concepts 4.25 Silberschatz, Galvin and Gagne 2002 Bounded-Buffer – Consumer Process item nextConsumed; while (1) { while (in == out) ; /* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; } Operating System Concepts 4.26 Silberschatz, Galvin and Gagne 2002 Interprocess Communication (IPC) 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) Operating System Concepts 4.27 Silberschatz, Galvin and Gagne 2002 Implementation Questions How are links established? Can a link be associated with more than two processes? How many links can there be between every pair of communicating processes? What is the capacity of a link? Is the size of a message that the link can accommodate fixed or variable? Is a link unidirectional or bi-directional? Operating System Concepts 4.28 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.29 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.30 Silberschatz, Galvin and Gagne 2002 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 Operating System Concepts 4.31 Silberschatz, Galvin and Gagne 2002 Indirect Communication Mailbox sharing P1, P2, and P3 share mailbox A. P1, sends; P2 and P3 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. Operating System Concepts 4.32 Silberschatz, Galvin and Gagne 2002 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 Operating System Concepts 4.33 Silberschatz, Galvin and Gagne 2002 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. Operating System Concepts 4.34 Silberschatz, Galvin and Gagne 2002 Client-Server Communication Sockets Remote Procedure Calls Remote Method Invocation (Java) Operating System Concepts 4.35 Silberschatz, Galvin and Gagne 2002 Sockets A socket is defined as an endpoint for communication. Concatenation of IP address and port The socket 161.25.19.8:1625 refers to port 1625 on host 161.25.19.8 Communication consists between a pair of sockets. Operating System Concepts 4.36 Silberschatz, Galvin and Gagne 2002 Socket Communication Operating System Concepts 4.37 Silberschatz, Galvin and Gagne 2002 Remote Procedure Calls Remote procedure call (RPC) abstracts procedure calls between processes on networked systems. Stubs – client-side proxy for the actual procedure on the server. The client-side stub locates the server and marshalls the parameters. The server-side stub receives this message, unpacks the marshalled parameters, and peforms the procedure on the server. Operating System Concepts 4.38 Silberschatz, Galvin and Gagne 2002 Execution of RPC Operating System Concepts 4.39 Silberschatz, Galvin and Gagne 2002 Remote Method Invocation Remote Method Invocation (RMI) is a Java mechanism similar to RPCs. RMI allows a Java program on one machine to invoke a method on a remote object. Operating System Concepts 4.40 Silberschatz, Galvin and Gagne 2002 Marshalling Parameters Operating System Concepts 4.41 Silberschatz, Galvin and Gagne 2002 Operating System MCQS Operating System Concepts 4.42 Silberschatz, Galvin and Gagne 2002 Basic OS Introduction 1.What is operating system? a) collection of programs that manages hardware resources b) system service provider to the application programs c) link to interface the hardware and application programs d) all of the mentioned 2. To access the services of operating system, the interface is provided by the a) system calls b) API c) library d) assembly instructions 3.Which one of the following is not true? a) kernel is the program that constitutes the central core of the operating system b) kernel is the first part of operating system to load into memory during booting c) kernel is made of various modules which cannot be loaded in running operating system d) kernel remains in the memory during the entire computer session Operating System Concepts 4.43 Silberschatz, Galvin and Gagne 2002 4. Which one of the following error will be handle by the operating system? a) power failure b) lack of paper in printer c) connection failure in the network d) all of the mentioned 5. The main function of the command interpreter is a) to get and execute the next user-specified command b) to provide the interface between the API and application program c) to handle the files in operating system d) none of the mentioned 6. By operating system, the resource management can be done via a) time division multiplexing b) space division multiplexing c) both (a) and (b) d) none of the mentioned Operating System Concepts 4.44 Silberschatz, Galvin and Gagne 2002 7. If a process fails, most operating system write the error information to a a) log file b) another running process c) new file d) none of the mentioned 8. Which facility dynamically adds probes to a running system, both in user processes and in the kernel? a) DTrace b) DLocate c) DMap d) Dadd 9. Which one of the following is not a real time operating system? a) VxWorks b) Windows CE c) RTLinux d) Palm OS Operating System Concepts 4.45 Silberschatz, Galvin and Gagne 2002 10. The OS X has a) monolithic kernel b) hybrid kernel c) microkernel d) monolithic kernel with modules Operating System Concepts 4.46 Silberschatz, Galvin and Gagne 2002 MCQS on Process 1. The systems which allows only one process execution at a time, are called a) uniprogramming systems b) uniprocessing systems c) unitasking systems d) none of the mentioned 2. In operating system, each process has its own a) address space and global variables b) open files c) pending alarms, signals and signal handlers d) all of the mentioned 3. In Unix, Which system call creates the new process? a) fork b) create c) new d) none of the mentioned Operating System Concepts 4.47 Silberschatz, Galvin and Gagne 2002 4. A process can be terminated due to a) normal exit b) fatal error c) killed by another process d) all of the mentioned 5. What is the ready state of a process? a) when process is scheduled to run after some execution b) when process is unable to run until some task has been completed c) when process is using the CPU d) none of the mentioned 6. What is interprocess communication? a) communication within the process b) communication between two process c) communication between two threads of same process d) none of the mentioned Operating System Concepts 4.48 Silberschatz, Galvin and Gagne 2002 7. A set of processes is deadlock if a) each process is blocked and will remain so forever b) each process is terminated c) all processes are trying to kill each other d) none of the mentioned 8. A process stack does not contain a) function parameters b) local variables c) return addresses d) PID of child process 9. Which system call returns the process identifier of a terminated child? a) wait b) exit c) fork d) get 10. The address of the next instruction to be executed by the current process is provided by the a) CPU registers b) program counter c) process stack Operating System Concepts 4.49 Silberschatz, Galvin and Gagne 2002 MCQS on Process Control Block 1) A Process Control Block(PCB) does not contain which of the following : a) Code b) Stack c) Heap d) Data e) Program Counter f) Process State g) I/O status information h) bootstrap program 2) The number of processes completed per unit time is known as __________. a) Output b) Throughput c) Efficiency d) Capacity Operating System Concepts 4.50 Silberschatz, Galvin and Gagne 2002 3) The state of a process is defined by : a) the final activity of the process b) the activity just executed by the process c) the activity to next be executed by the process d) the current activity of the process 4) Which of the following is not the state of a process ? a) New b) Old c) Waiting d) Running e) Ready f) Terminated 5) The Process Control Block is : a) Process type variable b) Data Structure c) a secondary storage section d) a Block in memory Operating System Concepts 4.51 Silberschatz, Galvin and Gagne 2002 6) The entry of all the PCBs of the current processes is in a) Process Register b) Program Counter c) Process Table d) Process Unit 7) The degree of multi-programming is : a) the number of processes executed per unit time b) the number of processes in the ready queue c) the number of processes in the I/O queue d) the number of processes in memory 8) A single thread of control allows the process to perform a) only one task at a time b) multiple tasks at a time c) All of these 9) The objective of multi-programming is to : (choose two) a) Have some process running at all times b) Have multiple programs waiting in a queue ready to run c) To minimize CPU utilization d) To maximize CPU utilization Operating System Concepts 4.52 Silberschatz, Galvin and Gagne 2002 Process Scheduling Queues 1) Which of the following do not belong to queues for processes ? a) Job Queue b) PCB queue c) Device Queue d) Ready Queue 2) When the process issues an I/O request : a) It is placed in an I/O queue b) It is placed in a waiting queue c) It is placed in the ready queue d) It is placed in the Job queue 3) When a process terminates : (Choose Two) a) It is removed from all queues b) It is removed from all, but the job queue c) Its process control block is de-allocated d) Its process control block is never de-allocated Operating System Concepts 4.53 Silberschatz, Galvin and Gagne 2002 4) What is a long-term scheduler ? a) It selects which process has to be brought into the ready queue b) It selects which process has to be executed next and allocates CPU c) It selects which process to remove from memory by swapping d) None of these 5) If all processes I/O bound, the ready queue will almost always be ______, and the Short term Scheduler will have a ______ to do. a) full,little b) full,lot c) empty,little d) empty,lot 6) What is a medium-term scheduler ? a) It selects which process has to be brought into the ready queue b) It selects which process has to be executed next and allocates CPU c) It selects which process to remove from memory by swapping d) None of these Operating System Concepts 4.54 Silberschatz, Galvin and Gagne 2002 7) What is a short-term scheduler ? a) It selects which process has to be brought into the ready queue b) It selects which process has to be executed next and allocates CPU c) It selects which process to remove from memory by swapping d) None of these 8) The primary distinction between the short term scheduler and the long term scheduler is : a) The length of their queues b) The type of processes they schedule c) The frequency of their execution d) None of these 9) The only state transition that is initiated by the user process itself is : a) block b) wakeup c) dispatch d) None of these Operating System Concepts 4.55 Silberschatz, Galvin and Gagne 2002 10) In a time-sharing operating system, when the time slot given to a process is completed, the process goes from the running state to the : a) Blocked state b) Ready state c) Suspended state d) Terminated state 11) In a multi-programming environment : a) the processor executes more than one process at a time b) the programs are developed by more than one person c) more than one process resides in the memory d) a single user can execute many programs at the same time 12) Suppose that a process is in “Blocked” state waiting for some I/O service. When the service is completed, it goes to the : a) Running state b) Ready state c) Suspended state d) Terminated state Operating System Concepts 4.56 Silberschatz, Galvin and Gagne 2002 13) The context of a process in the PCB of a process does not contain : a) the value of the CPU registers b) the process state c) memory-management information d) context switch time 14) Which of the following need not necessarily be saved on a context switch between processes ? (GATE CS 2000) a) General purpose registers b) Translation look-aside buffer c) Program counter d) All of these 15) Which of the following does not interrupt a running process ? (GATE CS 2001) a) A device b) Timer c) Scheduler process d) Power failure Operating System Concepts 4.57 Silberschatz, Galvin and Gagne 2002 16) Several processes access and manipulate the same data concurrently and the outcome of the execution depends on the particular order in which the access takes place, is called a(n) _____ a) Shared Memory Segments b) Entry Section c) Race condition d) Process Synchronization 17) Which of the following state transitions is not possible ? a) blocked to running b) ready to running c) blocked to ready d) running to blocked Operating System Concepts 4.58 Silberschatz, Galvin and Gagne 2002 Process Creation 1) Restricting the child process to a subset of the parent’s resources prevents any process from : a) overloading the system by using a lot of secondary storage b) under-loading the system by very less CPU utilization c) overloading the system by creating a lot of sub-processes d) crashing the system by utilizing multiple resources 2) A parent process calling _____ system call will be suspended until children processes terminate. a) wait b) fork c) exit d) exec Operating System Concepts 4.59 Silberschatz, Galvin and Gagne 2002 3) Cascading termination refers to termination of all child processes before the parent terminates ______. a) Normally b) Abnormally c) Normally or abnormally d) None of these 4) With ……………. only one process can execute at a time; meanwhile all other process are waiting for the processor. With ………….. more than one process can be running simultaneously each on a different processor. a) Multiprocessing, Multiprogramming b) Multiprogramming, Uniprocessing c) Multiprogramming, Multiprocessing d) Uniprogramming, Multiprocessing 5) In UNIX, each process is identified by its : a) Process Control Block b) Device Queue c) Process Identifier d) None of these Operating System Concepts 4.60 Silberschatz, Galvin and Gagne 2002 6) In UNIX, the return value for the fork system call is _____ for the child process and _____ for the parent process. a) A Negative integer, Zero b) Zero, A Negative integer c) Zero, A nonzero integer d) A nonzero integer, Zero 7) The child process can : (choose two) a) be a duplicate of the parent process b) never be a duplicate of the parent process c) have another program loaded into it d) never have another program loaded into it 8) The child process completes execution, but the parent keeps executing, then the child process is known as : a) Orphan b) Zombie c) Body d) Dead Operating System Concepts 4.61 Silberschatz, Galvin and Gagne 2002