CITS2002 Systems Programming |
CITS2002 | CITS2002 schedule | |||||
ProcessesThe fundamental activity of an operating system is the creation, management, and termination of processes. What is a process? Naively:
CITS2002 Systems Programming, Lecture 8, p1, 14th August 2024.
Process StatesWe can view the process from two points of view: that of the processor, and that of the process itself.
We've already identified two possible process states that a process may be in at any one time: Running and Ready. Question: Can a process determine in what state it is?
CITS2002 Systems Programming, Lecture 8, p2, 14th August 2024.
Process TransitionsThe operating system's role is to manage the execution of existing and newly created processes by moving them between the two states until they finish. So we have a simple model consisting of two recurring steps:
For simplicity (of both understanding and implementation) modern operating
systems support the idle process which is always ready to run,
and never terminates.
CITS2002 Systems Programming, Lecture 8, p3, 14th August 2024.
The Simple 2-state Process ModelAs we generally have more than two processes available, the Ready state is implemented as a queue of available processes:
CITS2002 Systems Programming, Lecture 8, p4, 14th August 2024.
Process CreationIn supporting the creation of a new process, the operating system must allocate resources both for the process and the operating system itself. The process (program under execution) will require a portion of the available memory to contain its (typically, read-only) instructions and initial data requirements. As the process executes, it will demand additional memory for its execution stack and its heap. The operating system (as dispatcher) will need to maintain some internal control structures to support the migration of the process between states. Where do new processes come from?
CITS2002 Systems Programming, Lecture 8, p5, 14th August 2024.
Process TerminationStallings summarises typical reasons why a process will terminate:
CITS2002 Systems Programming, Lecture 8, p6, 14th August 2024.
Timer InterruptsWhy does a process move from Running to Ready? The operating system must meet the two goals of fairness amongst processes and maximal use of resources (here, the processor and, soon, memory). The first is easily met: enable each process to execute for a predetermined period before moving the Running process to the Ready queue.
CITS2002 Systems Programming, Lecture 8, p7, 14th August 2024.
The Blocking of ProcessesThe above scenario is simple and fair if all Ready processes are always truly ready to execute. However, the existence of processes which continually execute to the end of their time quanta, often termed compute-bound processes, is rare. More generally, a process will request some input or output (I/O) from a comparatively slow source (such as a disk drive, tape, keyboard, mouse, or clock). Even if the "reply" to the request is available immediately, a synchronous check of this will often exceed the remainder of the process's time quantum. In general the process will have to wait for the request to be satisfied. The process should no longer be Running, but it is not Ready either: at least not until its I/O request can be satisfied. We now introduce a new state for the operating system to support, Blocked, to describe processes waiting for I/O requests to be satisfied. A process requesting I/O will, of course, request the operating system to undertake the I/O, but the operating system supports this as three activities:
CITS2002 Systems Programming, Lecture 8, p8, 14th August 2024.
The 5-State Model of Process ExecutionAt this point, Stallings introduces his 5-state model:
CITS2002 Systems Programming, Lecture 8, p9, 14th August 2024.
Supporting Multiple Blocked StatesWhen notification of an I/O or timer completion occurs, the simplest queuing model requires the operating system to scan its Blocked queue to determine which process(es) requested, or are interested in, the event:
CITS2002 Systems Programming, Lecture 8, p10, 14th August 2024.
Supporting Multiple Blocked States, continuedA better scheme is to maintain a queue for each possible event type. When an event occurs, its (shorter) queue is scanned more quickly:
CITS2002 Systems Programming, Lecture 8, p11, 14th August 2024.
The Dispatching Role of Operating SystemsAs should now be clear, this view of the operating system as a dispatcher involves the moving of processes from one execution state to another. The process's state is reflected by where it resides, although its state will also record much other information. The possible state transitions that we have now discussed are:
CITS2002 Systems Programming, Lecture 8, p12, 14th August 2024.
Suspension of ProcessesRecall that the processor is much faster than I/O. As a consequence, it is quite possible for all processes to be blocked on I/O requests, when the processor will be idle most of the time while waiting for I/O interrupts. Question: How to get more executing processes, given that resources such as memory are finite? To enable more true work to be performed by the processor, we could provide more memory to support the requirements of more processes.
CITS2002 Systems Programming, Lecture 8, p13, 14th August 2024.
Swapping of ProcessesAnother solution is swapping: moving (part of) a process's memory to disk when it is not needed. When none of the processes in main memory is Ready and more memory is required, the operating system swaps the memory of some of the Blocked processes to disk to reclaim some memory space. Such processes are moved to a new state: the Suspend state, a queue of processes that have been "kicked out" of main memory:When memory becomes available, the operating system may now resume execution of a process from Suspend, or admit a process from New to Ready.
CITS2002 Systems Programming, Lecture 8, p14, 14th August 2024.
|