Process abstraction
A process is an instance of a program running on a computer.
OS needs to keep track of information to represent a process:
- Memory Program code, data, etc.
- Resources in use I/O in use, physical memory, etc.
- Execution state Register set, current process state, etc.
The process's view of it's memory, a range of memory locations:
- Text segment Stores program code
- Data segment Stores global / static vars
- Heap Stores dynamically allocated memory
- Stack Stores local vars and function call info
Process control
The PCB (or Process descriptor) is a data structure used by the OS to represent a process. It contains:
- Process ID (PID)
- Process state
- Program counter (address of next instruction)
- Register context (snapshot of register contents when process was last in running state)
- Scheduling information (e.g. process priority, pointers etc.)
- etc.
- Table where OS keeps pointers to each process's PCB
- When a process is completely terminated, OS removes process from process table and frees up all used resources
- OS maintains a Ready list and a Blocked list that stores references to the PCBs of processes that are not running
Process lifecycle
How to create a new process:
- A process spawns a new process
- Forming a tree of processes with parent and child relationship
Actions taken:
- Assign unique PID
- Allocate memory for process
- Initialize PCB
- Add process to Ready list
System call: fork() creates a new process by duplicating the calling process. The child process gets a unique PID and a copy of the parent's address space.
exec() replaces the current process's address space with a new program. It is often used after fork() to run a different program in the child process.
- Self termination:
exit()or return from main - Process may terminate in response to a signal, error or fault
- Parent can obtain information from terminated child via
wait(),waitid()orwaitpid()- Zombie process: Any terminated process in this state is a zombie process
- Child resources & PCB is kept until only after parent has collected information about the child
- Any child processes will normally be kept alive and not terminated
- Temporarily deactivate the process so it is not being considered for processor scheduling.
- Suspension only happes externally:
- Request by parent process
- OS can suspend a blocked process to free up memory for another ready process
- Must be resumed externally

Signals
Used to notify a process about a particular event from another software entity.
Each signal is represented by a value & symbolic name.
Triggered by current instruction of the current running process itself, and delivered to that process by the OS immediately.
For example:
- SIGSEGV (11) - Segmentation fault
Generated by external events, arriving at unpredictable times.
For example:
- By timer alarm
- Parent using
kill()system call to kill child process
To deliver a signal from process X to process Y:
- X: Execute system call
- Switch to kernel mode
- OS: Deliver signal to Y
- Y: Handle signal
- Y: Return to user mode
Processes can handle signals in several ways:
-
Ignore: Inform OS that it does not want to handle the signal
-
Catch: Specify a signal handler function in advance, so OS will invoke it when the signal is delivered. The
signal()orsigaction()system calls are used to set up signal handlers. -
Default: Use the default action to handle signal
-
Mask: Instruct OS not to deliver signals of that type until process clears the signal mask
The SIGKILL and SIGSTOP signals cannot be caught, blocked or ignored.
Determining what a process should do when a signal is delivered:
- A process's PCB contains pointer to a vector of signal handlers. Each entry corresponds to the handler function for that entry's signal
- A child process inherits the parent's signal handlers, unless
exec()is called to replace the process's address space
