Processes Basics

What is a process

  • A process is an instance of an executing program.
  • A program is a file containing a range of information that describes how to construct a process at run time:
    • Machine-language instructions: These encode the algorithm of the program.
    • Data: The program file contains values used to initialize variables and also literal constants used by the program (e.g., strings).
    • Shared-library and dynamic-linking information
  • We have already seen that ls command is actually a program:
1$ ls -l /usr/bin/ls
2-rwxr-xr-x 1 root root 142280 Jan 10  2023 /usr/bin/ls
3$ file /usr/bin/ls
4/usr/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=6e45645c07d892b7b01c04b0522cf5b0e10c9e52, for GNU/Linux 3.2.0, stripped
5$
  • Each time we run ls, we are creating a process that executes that code that is embedded in that file, thus creating a process.

Looking at processes with the ps command

  • The ls program is creating processes that are short lived. In most cases the process finds the file it should show, writes that on the screen and exit. Then the process ends.
  • Other processes live longer, in most cases waiting for some event that should be handled.
  • You can look at processes by using the ps command:
 1$ ps -A
 2    PID TTY          TIME CMD
 3      1 ?        00:00:02 systemd
 4      2 ?        00:00:00 kthreadd
 5      3 ?        00:00:00 rcu_gp
 6      4 ?        00:00:00 rcu_par_gp
 7    355 ?        00:00:00 irq/18-vmwgfx
 8   3323 ?        00:00:00 VBoxClient
 9   3427 ?        00:00:00 update-notifier
10   3468 ?        00:00:06 terminator
11   3491 pts/0    00:00:00 bash
12   3759 ?        00:00:00 kworker/2:2
13   3801 ?        00:00:00 kworker/3:0-mm_percpu_wq
14   3811 ?        00:00:00 kworker/u10:0-events_power_efficient
15   3817 ?        00:00:00 kworker/u10:1-events_power_efficient
16   3827 ?        00:00:00 kworker/1:2
17   3834 ?        00:00:00 kworker/u10:2-events_unbound
18   3837 pts/0    00:00:00 ps
  • Note that we see the ps command process itself here, as it is currently still running
  • Each process has its own Process ID, starting with 1 (for a process called systemd)
  • Note process 3491 running bash:
    This is the shell running at the terminal window we are currently useing.
    (we'll talk allot about the shell in other posts)