Created: 2023-07-22 19:33
Status: #concept
Subject: Programming System Administration
Tags: Linux Operating System Bash Process Management BIOS Bootloader
Kernel
It is the core of the Operating System that manages Hardware and tells it how to interact with the system.
- it initializes devices & memory, then loads the init process.
$ uname -r # shows the kernel version
$ sudo apt dist-upgrade # upgrades our kernel
It knows:
- The status of the process
- The resources the process is using and receives
- The process owner
- Signal handling (more on that later)
- And basically everything else
/proc
Directory
Everything in Linux is a file, even processes, which are found in
/proc
.
- we can find
PID
process statuses in their/proc/<pid>/status
file.
$ cat /proc/12345/status
Process States
We use
ps aux
and check the STAT
column for information on a process's state.
R
: Running or runnable, it is just waiting for the CPU to process it.S
: Interruptible sleep, waiting for an event to complete, such as input from the terminal.D
: Uninterruptible sleep, processes that cannot be killed or interrupted with a signal, usually to make them go away you have toreboot
or fix the issue.Z
: Zombie, terminated processes that are waiting to have their statuses collected by a parent.T
: Stopped, a process that has been suspended/stopped.
Process Creation
When a new process is created, an existing process clones itself using the
fork
System Call which creates a child process identical to the parent, but with a new Process ID (PID). When a system boots up, a persistent process called init is created (with the PID of
1
) which spawns many child processes.
Process Termination
A process can manually exit and deallocate the memory it uses using the
_exit
System Call along with a termination status code, similar to C's exit(0)
function.
- A parent process uses the
wait
System Call to figure out whether a child process has been killed.
Orphan Processes
When a parent process dies before a child process, the Kernel puts the children (now known as Orphan Processes) under the care of
init
.
init
will not be responsible for calling thewait
System Call to figure out whether the child processes_exit
.
Zombie Processes
When a child terminates and a parent process didn't call
wait
to listen for the _exit
System Call, the Kernel turns the child processes into Zombie Processes.
- the resources of the child are freed up, however there is still an entry in the Process Table for the zombie process.
- they cannot be killed with signals because they are already dead and have no resources to free.
- eventually, in a process called "reaping", when the parent calls the
wait
System Call on the zombie process, the zombie will disappear