CHAPTER 3 PROCESS MANAGEMENT Unit Structure 3.0 Objectives - TopicsExpress



          

CHAPTER 3 PROCESS MANAGEMENT Unit Structure 3.0 Objectives 3.1 Concept of Process 3.1.1 Processes and Programs 3.2 Process State 3.2.1 Suspended Processes 3.2.2 Process Control Block 3.3 Process Management 3.3.1 Scheduling Queues 3.3.2 Schedulers 3.4 Context Switching 3.5 Operation on processes 3.6 Co-operating Processes 3.7 Summary 3.8 Model Question To describe the various features of processes, including scheduling, creation and termination, and communication. 3.1 Concept of Process A process is sequential program in execution. A process defines the fundamental unit of computation for the computer . Components of process are : 1. Object Program 2. Data 3. Resources 4. Status of the process execution. Object program i.e. code to be executed. Data is used for executing the program. While executing the program, it may require some resources. Last component is used for verifying the status of the process execution. A process can run to completion only when all requested resources have been allocated to the process. Two or more processes could be executing the same program, each using their own data and resources. 3.1.1 Processes and Programs Process is a dynamic entity, that is a program in execution. A process is a sequence of information executions. Process exists in a limited span of time. Two or more processes could be executing the same program, each using their own data and resources. Program is a static entity made up of program statement. Program contains the instructions. A program exists at single place in space and continues to exist. A program does not perform the action by itself. 3.2 Process State When process executes, it changes state. Process state is defined as the current activity of the process. Fig. 3.1 shows the general form of the process state transition diagram. Process state contains five states. Each process is in one of the states. The states are listed below. 1. New 2. Ready 3. Running 4. Waiting 5. Terminated(exist) 1. New : A process that just been created. 2. Ready : Ready processes are waiting to have the processor allocated to them by the operating system so that they can run. 3. Running : The process that is currently being executed. A running process possesses all the resources needed for its execution, including the processor. 4. Waiting : A process that can not execute until some event occurs such as the completion of an I/O operation. The running process may become suspended by invoking an I/O module. 5. Terminated : A process that has been released from the pool of executable processes by the operating system. Whenever processes changes state, the operating system reacts by placing the process PCB in the list that corresponds to its new state. Only one process can be running on any processor at any instant and many processes may be ready and waiting state. 3.2.1 Suspended Processes Characteristics of suspend process 1. Suspended process is not immediately available for execution. 2. The process may or may not be waiting on an event. 3. For preventing the execution, process is suspend by OS, parent process, process itself and an agent. 4. Process may not be removed from the suspended state until the agent orders the removal. Swapping is used to move all of a process from main memory to disk. When all the process by putting it in the suspended state and transferring it to disk. Reasons for process suspension 1. Swapping 2. Timing 3. Interactive user request 4. Parent process request Swapping : OS needs to release required main memory to bring in a process that is ready to execute. Timing : Process may be suspended while waiting for the next time interval. Interactive user request : Process may be suspended for debugging purpose by user. Parent process request : To modify the suspended process or to coordinate the activity of various descendants. 3.2.2 Process Control Block (PCB) Each process contains the process control block (PCB). PCB is the data structure used by the operating system. Operating system groups all information that needs about particular process. Fig. 3.2 shows the process control block. Pointer Process State Process Numb er Program Coun ter CPU registers Memory Alloc ation Event Informat ion List of open fil es Fig. 3.2 Process Control Block 1. Pointer : Pointer points to another process control block. Pointer is used for maintaining the scheduling list. 2. Process State : Process state may be new, ready, running, waiting and so on. 3. Program Counter : It indicates the address of the next instruction to be executed for this process. 4. Event information : For a process in the blocked state this field contains information concerning the event for which the process is waiting. 5. CPU register : It indicates general purpose register, stack pointers, index registers and accumulators etc. number of register and type of register totally depends upon the computer architecture. 6. Memory Management Information : This information may include the value of base and limit register. This information is useful for deallocating the memory when the process terminates. 7. Accounting Information : This information includes the amount of CPU and real time used, time limits, job or process numbers, account numbers etc. Process control block also includes the information about CPU scheduling, I/O resource management, file management information, priority and so on. The PCB simply serves as the repository for any information that may vary from process to process. When a process is created, hardware registers and flags are set to the values provided by the loader or linker. Whenever that process is suspended, the contents of the processor register are usually saved on the stack and the pointer to the related stack frame is stored in the PCB. In this way, the hardware state can be restored when the process is scheduled to run again. 3.3 Process Management / Process Scheduling Multiprogramming operating system allows more than one process to be loaded into the executable memory at a time and for the loaded process to share the CPU using time multiplexing. The scheduling mechanism is the part of the process manager that handles the removal of the running process from the CPU and the selection of another process on the basis of particular strategy. 3.3.1 Scheduling Queues When the process enters into the system, they are put into a job queue. This queue consists of all processes in the system. The operating system also has other queues. Device queue is a queue for which a list of processes waiting for a particular I/O device. Each device has its own device queue. Fig. 3.3 shows the queuing diagram of process scheduling. In the fig 3.3, queue is represented by rectangular box. The circles represent the resources that serve the queues. The arrows indicate the flow of processes in the system. Fig. 3.3 Queuing Diagram Queues are of two types : ready queue and set of device queues. A newly arrived process is put in the ready queue. Processes are waiting in ready queue for allocating the CPU. Once the CPU is assigned to the process, then process will execute. While executing the process, one of the several events could occur. 1. The process could issue an I/O request and then place in an I/O queue. 2. The process could create new sub process and waits for its termination. 3. The process could be removed forcibly from the CPU, as a result of interrupt and put back in the ready queue. 3.3.1.1 Two State Process Model Process may be in one of two states : a) Running b) Not Running when new process is created by OS, that process enters into the system in the running state. Processes that are not running are kept in queue, waiting their turn to execute. Each entry in the queue is a printer to a particular process. Queue is implemented by using linked list. Use of dispatcher is as follows. When a process interrupted, that process is transferred in the waiting queue. If the process has completed or aborted, the process is discarded. In either case, the dispatcher then select a process from the queue to execute. 3.3.2 Schedules Schedulers are of three types. 1. Long Term Scheduler 2. Short Term Scheduler 3. Medium Term Scheduler 3.2.2.1 Long Term Scheduler It is also called job scheduler. Long term scheduler determines which programs are admitted to the system for processing. Job scheduler selects processes from the queue and loads them into memory for execution. Process loads into the memory for CPU scheduler. The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound and processor bound. It also controls the degree of multiprogramming. If the degree of multiprogramming is stable, then the average rate of process creation must be equal to the average departure rate of processes leaving the system. On same systems, the long term scheduler may be absent or minimal. Timesharing operating systems have no long term scheduler. When process changes the state from new to ready, then there is a long term scheduler. 3.2.2.2 Short Term Scheduler It is also called CPU scheduler. Main objective is increasing system performance in accordance with the chosen set of criteria. It is the change of ready state to running state of the process. CPU scheduler selects from among the processes that are ready to execute and allocates the CPU to one of them. Short term scheduler also known as dispatcher, execute most frequently and makes the fine grained decision of which process to execute next. Short term scheduler is faster than long tern scheduler. 3.2.2.3 Medium Term Scheduler Medium term scheduling is part of the swapping function. It removes the processes from the memory. It reduces the degree of multiprogramming. The medium term scheduler is in charge of handling the swapped out-processes. Medium term scheduler is shown in the Fig. 3.4 Fig 3.4 Queueing diagram with medium term scheduler Running process may become suspended by making an I/O request. Suspended processes cannot make any progress towards completion. In this condition, to remove the process from memory and make space for other process. Suspended process is move to the secondary storage is called swapping, and the process is said to be swapped out or rolled out. Swapping may be necessary to improve the process mix. 3.2.2.4 Comparison between Scheduler Sr. No. Long Term Short Term Medium Term 1 It is job scheduler It is CPU Scheduler It is swapping 2 Speed is less than short term scheduler Speed is very fast Speed is in between both 3 It controls degree of multiprogramming Less control over degree of multiprogramming Reduce the degree of multiprogramming. 4 Absent or minimal in time sharing system. Minimal in time sharing system. Time sharing system use medium term scheduler. 5 It select processes from pool and load them into memory for execution. It select from among the processes that are ready to execute. Process can be reintroduced into memory and its execution can be continued. 6 Process state is (New to Ready) Process state is (Ready to Running) - 7 Select a good process, mix of I/O bound and CPU bound. Select a new process for a CPU quite frequently. - 3.4 Context Switch When the scheduler switches the CPU from executing one process to executing another, the context switcher saves the content of all processor registers for the process being removed from the CPU in its process being removed from the CPU in its process descriptor. The context of a process is represented in the process control block of a process. Context switch time is pure overhead. Context switching can significantly affect performance, since modern computers have a lot of general and status registers to be saved. Content switch times are highly dependent on hardware support. Context switch requires ( n + m ) bXK time units to save the state of the processor with n general registers, assuming b store operations are required to save register and each store instruction requires K time units. Some hardware systems employ two or more sets of processor registers to reduce the amount of context switching time. When the process is switched the information stored is : 1. Program Counter 2. Scheduling Information 3. Base and limit register value 4. Currently used register 5. Changed State 6. I/O State 7. Accounting 3.5 Operation on Processes Several operations are possible on the process. Process must be created and deleted dynamically. Operating system must provide the environment for the process operation. We discuss the two main operations on processes. 1. Create a process 2. Terminate a process 3.5.1 Create Process Operating system creates a new process with the specified or default attributes and identifier. A process may create several new subprocesses. Syntax for creating new process is : CREATE ( processed, attributes ) Two names are used in the process they are parent process and child process. Parent process is a creating process. Child process is created by the parent process. Child process may create another subprocess. So it forms a tree of processes. When operating system issues a CREATE system call, it obtains a new process control block from the pool of free memory, fills the fields with provided and default parameters, and insert the PCB into the ready list. Thus it makes the specified process eligible to run the process. When a process is created, it requires some parameters. These are priority, level of privilege, requirement of memory, access right, memory protection information etc. Process will need certain resources, such as CPU time, memory, files and I/O devices to complete the operation. When process creates a subprocess, that subprocess may obtain its resources directly from the operating system. Otherwise it uses the resources of parent process. When a process creates a new process, two possibilities exist in terms of execution. 1. The parent continues to execute concurrently with its children. 2. The parent waits until some or all of its children have terminated. For address space, two possibilities occur: 1. The child process is a duplicate of the parent process. 2. The child process has a program loaded into it. 3.5.2 Terminate a Process DELETE system call is used for terminating a process. A process may delete itself or by another process. A process can cause the termination of another process via an appropriate system call. The operating system reacts by reclaiming all resources allocated to the specified process, closing files opened by or for the process. PCB is also removed from its place of residence in the list and is returned to the free pool. The DELETE service is normally invoked as a part of orderly program termination. Following are the resources for terminating the child process by parent process. 1. The task given to the child is no longer required. 2. Child has exceeded its usage of some of the resources that it has been allocated. 3. Operating system does not allow a child to continue if its parent terminates. 3.6 Co-operating Processes Co-operating process is a process that can affect or be affected by the other processes while executing. If suppose any process is sharing data with other processes, then it is called co-operating process. Benefit of the co-operating processes are : 1. Sharing of information 2. Increases computation speed 3. Modularity 4. Convenience Co-operating processes share the information : Such as a file, memory etc. System must provide an environment to allow concurrent access to these types of resources. Computation speed will increase if the computer has multiple processing elements are connected together. System is constructed in a modular fashion. System function is divided into number of modules. Behavior of co-operating processes is nondeterministic i.e. it depends on relative execution sequence and cannot be predicted a priori. Co-operating processes are also Reproducible. For example, suppose one process writes ―ABC‖, another writes ―CBA‖ can get different outputs, cannot tell what comes from which. Which process output first ―C‖ in ―ABCCBA‖. The subtle state sharing that occurs here via the terminal. Not just anything can happen, though. For example, ―AABBCC‖ cannot occur. 3.7 Summary A process is a program in execution. As a process executes, it changes state. The state of a process is defined by that process‘s current activity. Each process may be in one of the following states: new, ready, running, waiting, or terminated. Each process is represented in the operating system by its own process control block (PCB). A process, when it is not executing, placed in some waiting queue. There are two major classes of queues in an operating system: I/O request queues and the ready queue. The ready queue contains all the processes that are ready to execute and are waiting for the CPU. Each process is represented by a PCB and the PCBs can be linked together to form a ready queue. Long-term(job) scheduling is the selection of processes that will be allowed to contend for the CPU. Normally, longterm scheduling is heavily influenced by resources-allocation considerations, especially memory management. Short-term(CPU) scheduling is the selection of one process from the ready queue. Operating systems must provide a mechanism for parent processes to create new child processes. The parent may wait for its children to terminate before proceeding, or the parent and children may execute concurrently. There are several reasons for allowing concurrent execution: information sharing computation speedup, modularity, and convenience. The processes executing in the operating system may be either independent processes or cooperating processes. Cooperating processes require an inter-process communication mechanism to communicate with each other. Principally, communication is achieved through two schemes: shared memory and message passing. The shared-memory method requires communicating processes through the use of these shared variables. In a shared-memory system, the responsibility for providing communication rests with the application programmers: the operating system needs to provide only the shared memory. The responsibility for providing communication may rest with the operating system itself. These two schemes are not mutually exclusive and can be used simultaneously within a single operating system. 3.8 Model Question Q.1 Define process and programs? Q.2 Describe Process Control Block? Q.3 Explain Scheduling Queues? Q.4 Explain schedulers and its types? Q.5 Differentiate various types of scheduler? Q.6 Explain context switch? Q.7 Explain operation on processes?
Posted on: Mon, 30 Jun 2014 11:49:31 +0000

Trending Topics



Recently Viewed Topics




© 2015