Process
In Linux, a program is a passive set of machine code instructions and data stored in an executable image. A process can be thought of as this passive program in action.
Processes are independent separate tasks. If one process crashed, it will not affect any other processes.
The kernel manages resource allocation (such as the CPU) between different processes. This is done by the scheduler.
Process composition
Representing the execution of a program, a process includes the state of the program first and foremost. This includes
- The program counter
- CPU registers
- The process stack
Beyond the state of the program, each process is allocated its own process identifier (PID) and virtual memory among other things.
Lifetime of a process
Init process
When the computer starts, the only thing the kernel execute in the user space is a init command (shown with ps -f 1). This process is allocated a PID of 1 and is the only process with no parent process.
Creating a process
In contrast to the init process, all other processes are created by parent processes. This is done with fork and exec. First, the shell will run fork to create a cloned process from the current process, and exec replaces the program in the cloned process with another program.
Sources
- Linux documentation: https://tldp.org/LDP/tlk/tlk.html
- Linux processes, init, fork/exec, ps, kill, fg, bg, jobs: https://www.youtube.com/watch?v=TJzltwv7jJs