1 / 29

Chapter 3: Processes

Chapter 3: Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication. Process Concept. An operating system executes a variety of programs: Operating System’s code User programs or tasks

gabby
Download Presentation

Chapter 3: Processes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 3: Processes • Process Concept • Process Scheduling • Operations on Processes • Interprocess Communication

  2. Process Concept • An operating system executes a variety of programs: • Operating System’s code • User programs or tasks • Textbook uses the terms job and process almost interchangeably. • Process – a program in execution; process execution must progress in sequential fashion. • A process includes: • program counter • CPU registers • Stack, containing temporary variables • data section, containing global variables • A C++ source file on disk is not a process • Several processes can be associated with the same program

  3. 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 processor. • terminated: The process has finished execution.

  4. Diagram of Process State

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

  6. Process Control Block (PCB) new, ready, running, waiting, terminated Address of the next instruction to be executed General memory management information such as base and limit registers

  7. CPU Switch From Process to Process

  8. Process Scheduling • Some systems allow execution of only a single process at a time. Such are called uni-programming systems. • Others allow more than one process, concurrent execution of many processes. These are called multi-programming (or multi-processing, but not multi-processor) system. • In a multiprogramming system, the CPU switches automatically among processes running each for tens or hundreds of milliseconds. Hence, users can interact with each program.

  9. 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. Each device has its own queue. • Processes that reside in main memory that are ready to execute are put on the ready queue. • If a process issues an I/O request, it is placed in the corresponding I/O queue. • When a process terminates, it is removed from all queues and its PCB is deleted.

  10. Ready Queue And Various I/O Device Queues

  11. Representation of Process Scheduling

  12. Process Schedulers • The selection of processes from the queues is managed by schedulers. • Long-term scheduler (or job scheduler) – selects processes from a mass-storage (i.e., hard disk) device where they are spooled and loads them into memory for execution. • Short-term scheduler (or CPU scheduler) – selects which ready process that is already loaded into memory should be executed next and allocates CPU.

  13. 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. This corresponds to the number of processes in memory. • 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.

  14. Schedulers (Cont.) • Long-term scheduler should pick a relatively good mix of I/O- and CPU-bound processes so that the system resources are better utilized. • If all processes are I/O-bound, the ready queue will almost always be empty. • If all processes are CPU-bound, I/O queue will be almost always empty. • A balanced combination should be selected for system efficiency.

  15. 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. • Switching involves copying registers, local and global data, file buffers and other information to the PCB. • Context-switch time is overhead; the system does no useful work while switching. • Time is dependent on hardware support.

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

  17. 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 – terminating the children processes by a terminated parent process.

  18. 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 communicationlink between them • exchange messages via send/receive

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

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

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

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

  23. Indirect Communication • Mailbox sharing • P1, P2, and P3 share mailbox A. • P1, sends; P2and 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.

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

  25. Acknowledgement • After receiving a message, in order to inform sender of the receipt of the message, receiver sends an acknowledgement message. Process P sends a message to Process Q send (Q, message) receive (P, message) receive (Q, message) send (Q, “Acknowledgement”)

  26. Exception Conditions • Message system is useful in distributed environments since the probability of error during communication is larger than that of a single machine environment. • In a single machine environment, shared memory system is generally used. • If a communication error occurs, error recovery or exception condition handling must take place. • Possible errors are: • A process terminates • Lost messages • Scrambled messages

  27. Exception Conditions – Terminated Process P P Q Q waiting sender • A sender or receiver process may terminate before a message is processed. This situation will leave message that will never be received or processes waiting for messages that will never be sent. • In these cases, the operating system should either terminate P or notify P that Q has terminated. Receiver process (P) waits a message from Q that has terminated. Then P will be blocked forever. P sends a message to a terminated process. If P requires an acknowledgement from Q for further processing, P will be blocked forever.

  28. Exception Conditions – Lost Messages Q P The message is lost due to hardware or communication line failure. • P send a message to Q, which is lost somewhere in the link due to link failure. • In such cases, • The OS is responsible for detecting and responding by notifying the sending process that the message is lost, or • The sending process is responsible for detecting and should re-transmit the message. • The most common method for detecting lost messages is to use timeouts. For instance, if the acknowledgement signal does not arrive at the sending process in a specified time interval, it is assumed that the signal is lost and resent.

  29. Exception Conditions – Scrambled messages • Because of the noise in communication channels, the delivered message may be scrambled (modified) in on the way. Error checking codes are commonly used to detect this type of error.

More Related