7.5 Process Management


A process is a program in execution. A process needs some resources, including CPU, memory, files, and I/O devices, to accomplish its task. The operating system manages activities such as user programs and system programs. Each of these activities is in a process. A process is an instant of a program in execution. There are many processes can be running the same program. A process has state and context.

Process State
There are five possible states of a process:
New: the process is being created.
Running: the process is currently being executed by a processor
Waiting: the process is waiting for a specific event to occur before it can proceed.
Ready: process is ready for execution, but must waiting for a processor to become available.
Terminated: the process has finished execution.

7.5 Process Management




Figure showing Process States

Process Context
For each process, its process control block PCB is used to track the process's execution status. So process control block is a data structure including the following:
Program counter, indicates the address of the next instruction to be executed for this process
CPU registers,

7.5 Process Management


memory management information,
accounting ( time used, ID, ... )
I/O status ( such as file resources ),
scheduling data ( relative priority, etc. )
Process State (so running, suspended, etc. is simply a field in the PCB ).



Figure showing the Process Control Block Stack

7.5 Process Management


When a process changes from one state to another, the operating system updates the information in its PCB. When the process is terminated, the operating system removes it from the process table and frees the memory and any other resources allocated to the process so that they become available to other processes.

Process Scheduling
Process scheduling means changing the active PCB pointed to by the CPU.



Figure showing the CPU switching from one process to another

7.5 Process Management


The operating system carries out four types of process scheduling:
Long-term (high-level) scheduling: selects processes and loads them into memory for execution.
It determines which programs are admitted to the system for processing. Before accepting a new
program, the long-term scheduler must first decide whether the processor is able to cope effectively with
another process.
Medium-term scheduling: it is a mixture of CPU and memory resource management. It transfers a
process out of main memory and into virtual memory or vice-versa. This may occur when the operating
system needs to make space for a new process.
Short-term (low-level) scheduling: determines which process to execute next. This will occur each time
the currently running process is halted, determines which process to execute next. This will occur each
time the currently running process is halted. It contains three functions:
code to remove a process from the processor at the end of its run.
code to put a process on the ready queue.
code to take a process off the ready queue and run that process.
I/O scheduling: controls how input/output operations will be submitted to storage.