Programs in execution or running instances
- Foreground processes or Interactive processes are Initialized and controlled through a terminal session. A user connected to the system starts or initiate them.
- Background processes or Non-interactive or automatic processes – are not connected to a terminal and don’t expect any user input.
- Daemons: Special types of background processes that start at system startup or tasks (run as services) and keep running forever as a service and don’t die. However, could be controlled by a user via the init process.
Each running instance of a program is identified uniquely by the kernel, by its process ID (PID) as well as its parent processes ID (PPID), which may be an exact copy of the existing process running within same environment in memory.
The processes are created using functions:
- System() – relatively simple, however, inefficient and has significantly security risks
- fork() and exec() – advanced and offers greater flexibility, speed, together with security.
Process Types
- init – It is the first program executed when the Linux system boots up and started by the Kernel itself assigned ID 1. Hence, the parent of all processes on the system and manages them.
- Parent – Processes that create other processes during run-time.
- Child – Processes created by other processes during run-time
Process States
During execution, a process changes from one state to another depending on its environment/circumstances.
- Running – the current process
- Waiting – waiting for an event to occur or for a system resource.
- Interruptible waiting process – interrupted by signals
- Uninterruptible waiting processes – waiting directly on hardware conditions and cannot be interrupted by any event/signal
- Stopped – stopped by receiving a signal
- Zombie – a process is dead or halted but it still has an entry in the process table
[command] &
|
Execute command in background |
ctrl + c
|
Interrupt a program |
ctrl + z
|
Suspend a program and send it to the background |
bg
|
Sends a background process to the foreground |
kill [pid]
|
Kill the specified process |
kill -9 [pid]
|
Forcefully kill the specified process |
ps
|
List all processes |
pidof [Process-name]
|
To find the ID of a process like systemd, top, httpd |
echo $$
echo $PPID
|
To find the process ID and parent process ID of the current shell |
top
|
Monitor processes in real time |
glances
|
System Monitoring Tool with advanced features |