Key Concepts and Topics
Total Page:16
File Type:pdf, Size:1020Kb
Unit 2 (2.1 Processes) Chapter 3 Key Concepts and Topics: Process Process States New Running A process is the unit of work in a system. Such a system consists of a collection of concurrently executing processes, some of which are OS processes and the rest of which are user processes. As a process executes, it changes state. The state of a process is defined in part by the current activity of that process. A process may be in one of the following states: New, Running, Waiting, Ready and Terminated. New: The process is being created. Running: Instructions are being created. Waiting Ready Terminated Process Control Block Waiting: The process is waiting for some event to occur (such as an I/O completion or reception of a signal). Ready: The process is waiting to be assigned to a processor. Terminated: The process has finished execution. Each process is represented in the OS by a process control block also called a task control block. Process Scheduling Process Scheduler Job Scheduler CPU Scheduler The objective of multi-programming is to have some processes 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 for program execution on the CPU. Often, in a batch system, more processes are submitted than can be executed immediately. These processes are spooled to a mass-storage device, where they are kept for later execution. The job scheduler selects processes from this pool and loads them into memory for execution. The CPU scheduler selects from among the processes that are ready to execute and allocates the CPU to one of them. The key idea behind a medium-term scheduler is that sometimes it can be advantageous to remove a process from memory and thus reduce the degree of multiprogramming. Medium-Term Scheduler Swapping Context Switch Scheduling Queues A process that can be re-introduced into memory and have its execution continue where it left off is called swapping. The process is swapped out and later swapped in by the medium-term scheduler. Switching t he CPU to another process requires performing a state save of the current process and a state restore of a different process. This task is known as a context switch. When a context switch occurs, the kernel saves the context of the old process in its PCB and loads the saved context of the new process scheduled to run. As processes enter the system, they are put into a job queue, which consists of all processes in the system. The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. This queue is generally stored as a linked list. A ready-queue generally contains pointers to the first and final PCBs in the list. Each PCB includes a pointer field that points to the next PCB in the ready queue. [Scheduling Queues] Job Queue Ready Queue Device Queue Degree of Multiprogramming As processes enter the system, they are put into a job queue, which consists of all processes in the system. The processes that are residing in main memory and are ready and waiting to execute are kept on a list called the ready queue. The list of processes waiting for a particular I/O device is called a device queue. The Long-term scheduler executes much less frequently; minutes may separate the creation of one new process and the next. The long term scheduler controls the Degree of Multiprogramming (the number of processes in memory). Process Creation Fork() Process Termination In Unix, this process is called init. In Windows, it is the System Idle Process. This process is the parent or grand-parent of all other processes. New Child Processes are created by another process (the Parent Process). A new process is created by the fork() system call. The new process consists of a copy of the address space of the original process. A process terminates [ends] when it finishes executing its final statement and asks the operating system to delete it by using the exit() system call. Study questions. 1. What are the main features of processes? 2. What information is included in PCB? 3. What data structures are involved in process scheduling? 4. What is the rationale for each kind of scheduler: long term, short term and medium term schedulers? 5. How do you use fork() to create a process? The main features of processes include: Scheduling, creation and termination. 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. Creation: Starting a process. Termination: Finishing [ending] a process. What information is included in a PCB? Process Control Block is a data structure in the operating system kernel containing the information needed to manage a particular process. The PCB is "the manifestation of a process in an operating system. The role of the PCBs is central in process management: they are accessed and/or modified by most OS utilities, including those involved with scheduling, memory and I/O resource access and performance monitoring. It can be said that the set of the PCBs defines the current state of the operating system. Data structuring for processes is often done in terms of PCBs. For example, pointers to other PCBs inside a PCB allow the creation of those queues of processes in various scheduling states ("ready", "blocked", etc.) that we previously mentioned. What data structures are involved in process scheduling? array, file, record, tree What is the rationale for each kind of scheduler: long term, short term and medium term schedulers. Long Term Scheduling is heavily influenced by resource-allocation considerations, especially memory management. Short Term (CPU) Scheduling is the selection of one process from the ready queue. Medium Term Scheduling is the belief that sometimes it can be advantageous to remove a process from memory and thus reduce the degree of multiprogramming. How do you use fork() to create a process A new process is created by the fork () system. The new process consists of a copy of the address space of the original process. This mechanism allows the parent process to communicate easily with its child process. Both processes continue execution at the instruction after the fork( ), with one difference: the return code for the fork ( ) is zero [0] for the new (child) process, whereas the (nonzero) process identifier of the child is returned to the parent. Key Concepts and Topics: Process Cooperation Interprocess Communication Shared-Memory Message-Passing A process is Cooperating if it can affect or be affected by the other processes executing in the system Processes executing concurrently in the operating system may be either independent processes or cooperating processes. In the shared-memory model, a region of memory that is shared by cooperating processes is established. Message passing sends a message to a process and relies on the process and the supporting infrastructure to select and invoke the actual code to run. Message passing differs from conventional programming where a process, subroutine, or function is directly invoked by name. Message passing is key to some models of concurrency and object-oriented programming. Producer Consumer Problem Bounded & Unbounded buffer Direct and Indirect communication Naming The producer consumer problem provides a useful metaphor for the client-server paradigm. We generally think of a server as a producer and a client as a consumer. For example, a web server produces HTML files and images, which are consumed by the client web browser requesting the resource. The unbounded buffer places no practical limit on the size of the buffer. The consumer may have to wait for new items, but the producer can always produce new items. The bounded buffer assumes a fixed buffer size. In this case the consumer must wait if the buffer is empty, and the producer must wait if the buffer is full. Under Direct communication, each process that wants to communicate must explicitly name the recipient or sender of the communication. With indirect communication, the messages are sent and received from mailboxes, or ports. A mailbox can be viewed abstractly as an object into which messages can be placed by processes and from which messages can be removed. Processes that want to communicate must have a way to refer to each other. This can be accomplished by assigning an identity and/or identifier to each element. (i.e.) Naming Mailbox or Port Synchronization Buffering Zero bounded and Unbounded Capacity Messages are sent to and received from mailboxes, called ports in Mach. A process can communicate with another process via a number of different mailboxes, but two [2] processes can communicate only if they have a shared mailbox. Communication between processes takes place through calls to send () and receive () primitives. There are different design options for implementing each primitive. Message passing may be either blocking or unblocking also known as synchronous and asynchronous. A buffer, of course, is a memory area that stores data being transferred between two [2] devices or a device and an application. With zero bounded the queue has a maximum length of zero; thus, the link cannot have any messages waiting in it. In this case, the sender must block until the recipient receives a message. Unbounded capacity, the queue’s length is potentially infinite; thus any number of messages can wait in it.