Process Concept
- A process is an instance of a program in execution
Process Memory
- Text:
- comprises the compiled program code, read in from non-volatile storage when the program is launched.
- Data
- Stores global and static variables, allocated and initialized prior to executing main.
- Heap
- Used for dynamic memory allocation, is managed via calls to new, delete, malloc, free etc.
- Stack
- Used for local variables.
- 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 also used for function return values, and the exact mechanisms for stack management may be language specific.
- When processes are swapped out of memory and later restored, additional information must also be stored and restored. Key among them are the program counter and the value of all program registers.
Process State
- New
- The process is in the stage of being created.
- Ready
- The process has all the resources available that it needs to run, but the CPU is not currently working on this process’s instruction.
- Running
- The CPU is working on this process’s instruction.
- Waiting
- The process cannot run at the moment, because it is waiting for some resource to become available for some event to occur. For example, the process may be waiting for keyboard input, disk access request, inter-process messages, a time to go off, or a child process to finish.
- Terminated
- The process has completed.
Process Control Block
For each process, there is a Process Control Block (PCB), which stores the following (types of) process-specific information.
- Process State
- Running, waiting etc.
- Process ID
- and also parent process ID
- CPU registers and Program Counter
- These need to be saved to restored when swapping processes in and out of the CPU.
- CPU scheduling information
- Such as priority information and pointers to scheduling queues
- Memory-Management information
- e.g., page tables or segment tables
- Accounting information
- User and kernel CPU time consumed, account numbers, limits, etc.
- I/O Status information
- Devices allocated, open file tables etc.
Process Scheduling
- 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 program, particularly for interactive ones.
- The process scheduler must meet these objectives by implementing suitable policies for swapping process in and out of the CPU.
Scheduling Queues
- Job queue
- All processes are stored in the job queue.
- Ready queue
- Processes in the Ready state are placed in the ready queue
- Device queue
- Processes waiting for a device to be available or to deliver data are placed on device queues. There is generally a separate device queue for each device.
Scheduler
- Long-term scheduler
- Typically of a batch system or a very heavily loaded system. It runs infrequently, (such as when one process ends selecting one or more to be loaded in from disk in its place), and can afford to take the time to implement intelligent and advanced scheduling algorithms
- Short-term scheduler, or CPU scheduler
- Runs very frequently, on the order of 100 milliseconds, and must very quickly swap one process out of the CPU and swap in another one.
- Medium-term scheduler
- Some systems also employ medium-term scheduler.
- When system loads get high, this scheduler will swap one or more processes out of the ready queue system for a few seconds, in order to allow smaller faster jobs to finish up quickly and clear the system.
Reference
[1] https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/3_Processes.html