Single-tasking and multitasking
Single-tasking
Single-tasking is where the CPU would run one program at a time and that program could only do one thing at a time. This would require the program to be completely stopped to switch to another one.
Link to original
Multitasking
Multitasking is the ability for the CPU to switch between multiple tasks, allowing each of them to execute for a period of time. The CPU would still only execute one task at a time but could create the illusion that it was executing multiple tasks at the same time.
Link to original
Concurrency
The notion of concurrency is multiple tasks being able to make progress.
Link to original
Task (CPU)
A task is some activity that the CPU is undertaking.:
Link to original
- A CPU-bound task spends the majority of its time executing code on the CPU.
- An I/O-bound task spends a lot of time using I/O devices such as storage, network, etc.
Programs and Processes
We can define a program as the contents of an executable file.
ELF Executable Format
The ELF executable file format (used by Unix-systems) is contains:
- program instructions (“text”)
- constants (“rodata”)
- data (global data defined in program)
Link to original
Process (CPU)
A process is an instance of a program that is being executed by the computer.
Link to original
Launching Processes
When a computer system runs a process, it must create certain areas in the RAM. The code (text) and data segments from the executable file must be copied into RAM.
The OS also allocates two memory segments for each process incl the stack and heap.
Stack (Memory)
The stack is used to store local variables, method parameters, etc.
Link to original
Heap (Memory)
The heap is used for storing objects.
Link to original
The stack and heap are created by the OS and allow a process to dynamically create the necessary variables, parameters and objects. Code and data in the program are ‘static’ so the memory requirements don’t change but we do not know what the overall memory usage will be as the program may follow different code paths.
Local variables, method parameters, and objects created by malloc / new do not exist in the executable file and are not created until the program is running as a process and that section of code is called.
Process Memory Layout
The OS manages an area of RAM for each process that is running, it creates a block of memory in a similar structure to the figure below:

Memory addresses start at 0 and end at ‘max’. The arrows indicate that the stack and heap grow towards each other in the RAM, both of these structures are dynamic and can grow / shrink.
Process Control Block (PCB)
Process Control Block (Data Structure)
The Process Control Block (PCB) is a data structure in which the OS keeps data related to each process. The details vary for different operating systems but they largely include:
- Process Id: each process has a unique ID number
- Program counter: the address of the next instruction for the process
- Process state: whether the process is READY, WAITING, etc
- General purpose registers: contents of the CPU registers for the process
- List of open files / devices
PCBs are usually stored by the OS using a linked list.
Link to original
Process State
When a process is first created, its state is new. At this point the OS will decide whether to admit the new process, it might be forced to wait if the system is already fully committed.
Once a process has been admitted, it will transition to the ready state, waiting to be executed. When selected to execute via scheduler dispatch, the process will transition to the running state.
When a process is running, it may be interrupted by the OS to run another process. When running, a process might issue an I/O request of some kind in which case it will transition to the waiting state, once complete it will be put back in the ready queue.
When the process exists it will transition to terminated state.


