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:

/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.

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).

  • it contains Metadata of the parent process ID (PPID).
  • it can continue to use the parent program or start a new one with the execve System Call to launch a new program and reallocating new Memory.

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 the wait 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

References