A long-term scheduler is typical of a batch system or a very heavily loaded system.The ready queue and various I/O device queues 3.2.2 Schedulers Other queues may also be created and used as needed.There is generally a separate device queue for each device. Processes waiting for a device to become available or to deliver data are placed in device queues.Processes in the Ready state are placed in the ready queue.All processes are stored in the job queue.In particular, every time the system steps in to swap processes it takes up time on the CPU to do so, which is thereby "lost" from doing any useful productive work. ( Note that these objectives can be conflicting.The process scheduler must meet these objectives by implementing suitable policies for swapping processes in and out of the CPU.The two main objectives of the process scheduling system are to keep the CPU busy at all times and to deliver "acceptable" response times for all programs, particularly for interactive ones.Threads are covered extensively in the next chapter. Modern systems allow a single process to have multiple threads of execution, which execute concurrently.Unnumbered side bar Digging Deeper: The Linux task_struct definition in sched.h ( See also the top of that file. I/O Status information - Devices allocated, open file tables, etc.įigure 3.3 - Process control block ( PCB )įigure 3.4 - Diagram showing CPU switch from process to process.Accounting information - user and kernel CPU time consumed, account numbers, limits, etc.CPU-Scheduling information - Such as priority information and pointers to scheduling queues.CPU registers and Program Counter - These need to be saved and restored when swapping processes in and out of the CPU.Process State - Running, waiting, etc., as discussed above.( Specific details may vary from system to system. Some systems may have other states besides the ones listed here.įigure 3.2 - Diagram of process state 3.1.3 Process Control Blockįor each process there is a Process Control Block, PCB, which stores the following ( types of ) process-specific information, as illustrated in Figure 3.1.processes who have everything they need to run but cannot because the CPU is busy doing something else. The load average reported by the "w" command indicate the average number of processes in the "Ready" state over the last 1, 5, and 15 minutes, i.e.Terminated - The process has completed.For example the process may be waiting for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to finish. Waiting - The process cannot run at the moment, because it is waiting for some resource to become available or for some event to occur.Running - The CPU is working on this process's instructions.Ready - The process has all the resources available that it needs to run, but the CPU is not currently working on this process's instructions.New - The process is in the stage of being created.Processes may be in one of 5 states, as shown in Figure 3.2 below.Key among them are the program counter and the value of all program registers.įigure 3.1 - A process in memory 3.1.2 Process State When processes are swapped out of memory and later restored, additional information must also be stored and restored.If they should ever meet, then either a stack overflow error will occur, or else a call to new or malloc will fail due to insufficient memory available.
MAXIMUM ACTION SAVED FREE
Note that the stack and the heap start at opposite ends of the process's free space and grow towards each other.Note that the stack is also used for function return values, and the exact mechanisms of stack management may be language specific. Space on the stack is reserved for local variables when they are declared ( at function entrance or elsewhere, depending on the language ), and the space is freed up when the variables go out of scope. The stack is used for local variables.The heap is used for dynamic memory allocation, and is managed via calls to new, delete, malloc, free, etc.The data section stores global and static variables, allocated and initialized prior to executing main.The text section comprises the compiled program code, read in from non-volatile storage when the program is launched.Process memory is divided into four sections as shown in Figure 3.1 below:.job scheduling ), and the two terms are often used interchangeably. Many modern process concepts are still expressed in terms of jobs, ( e.g. Batch systems work in terms of "jobs".A process is an instance of a program in execution.Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts, Ninth Edition ", Chapter 3.