Processes, step by step: from a file to an action.
How programs are installed and turned into processes, what states a process goes through, and how the shell connects processes to files, devices and each other.
Study material generated with AI (Claude) from the slides of ISO lecture 03, to be reviewed by the lecturers. It may contain mistakes; for the exam, the reference is the lecture and its slides. Found a mistake? Open an issue on the course repository.
About this material
How it was made
Text, figures, the simulators and the demo terminal were generated with Claude (Anthropic) from the slides of lecture 03 – Processes, following the structure of the interactive DEEA modules. The diagrams are the ones of the slides.
What was checked
The demo terminal was tested against the examples of the slides (redirects, pipes, links, /proc); its messages follow GNU coreutils and bash. Its process list and /proc are simulated. The redirect simulator follows what bash does in the child: the redirects from left to right with open, dup2 and close, then exec.
Mistakes
If you find one, open an issue with the page and the sentence. Version: November 2026.
Sources and contributors
Slides: USO Team, Copyright (C) 2026 Wyliodrin & Politehnica Bucharest, CC-BY-SA 4.0. Bibliography: the sources listed in the slides of the lecture.
Every program you use in the labs is installed from the repository of your distribution. Knowing what a package and a dependency are explains why apt asks for sudo, why it installs ten packages for one, and why removing a program leaves others behind.
🌐 Repository
A server of the distribution with thousands of checked and signed packages: a program, its files and the list of packages it needs (dependencies): cowsay → perl.
After install cowsay: cowsay and its dependency perl.
Fedora: dnf
$dnf search cowsayMatched fields: name (exact) cowsay.noarch Configurable speaking/thinking cow$sudo dnf install cowsayPackage Arch Version Repository SizeInstalling: cowsay noarch 0:3.8.4-5.fc44 fedora 80.5 KiBIs this ok [y/N]: y
Ubuntu: apt
$apt search cowsaycowsay/noble 3.03+dfsg2-8 all configurable talking cow$sudo apt install cowsayThe following NEW packages will be installed: cowsay libgdbm-compat4t64 libgdbm6t64 libperl5.38t64 libtext-charwidth-perl netbase perl perl-modules-5.38Do you want to continue? [Y/n] y
Why sudo
Installing changes the system for all the users, so it needs the administrator. The package manager shows what it will install and asks before it starts. noble is the name of Ubuntu 24.04.
cowsay needs perl
Dependencies are packages too
$which cowsay perl/usr/games/cowsay/usr/bin/perl$perl-e'print"hello from perl"'hello from perl$sudo apt remove cowsayThe following packages will be REMOVED: cowsay
cowsay is written in Perl: apt installed both
perl is a normal package: you, or any other program, can use it by itself
removing cowsay does not remove perl; sudo apt autoremove removes the dependencies nothing needs anymore
Cheat sheet
Fedora
Ubuntu
search
dnf search NAME
apt search NAME
details
dnf info NAME
apt show NAME
install
sudo dnf install NAME
sudo apt install NAME
remove
sudo dnf remove NAME
sudo apt remove NAME
remove unused dependencies
sudo dnf autoremove
sudo apt autoremove
update everything
sudo dnf upgrade
sudo apt update then sudo apt upgrade
apt update is not an upgrade
apt update only refreshes the list of packages; apt upgrade installs the new versions. dnf refreshes the list by itself.
Check yourself
You removed cowsay. Is perl still installed?
Files to actions
Executable vs. process
Why it matters
The operating system offers two abstractions: files for data and processes for actions. Every command you type becomes a process; most of the tools in this lecture (ps, redirects, /proc) look at or change one.
an executable is a file on the disk: /bin/ls
a process is a running instance of it, with its own memory, open files and PID
one executable can run as many processes at the same time: three terminals running bash are three processes of /usr/bin/bash
peripherals are files too (POSIX): /dev/sda the first disk, /dev/input/... the keyboard, /dev/fb0 the screen
one executable file, several processesprocesses (with threads and open files) on top of the kernel, which hides the hardware
The loader
Loading an executable
An executable file holds three things: how to load it, the code, and the list of libraries it needs. After exec, the loader uses all three to turn the file into a running process, in four steps: program loading, library loading, dynamic linking, execution.
The whole picture
PID, PPID, threads, files, memory
What a process has
PID and PPID identify it; threads run its code in parallel; the File Descriptor Table lists its open files and devices; memory holds the code and the variables
$echo $$ # the PID of the shell4100$ps-o pid,ppid,comm PID PPID COMMAND 4100 4090 bash 4301 4100 ps
$$ is the PID of the shell. ps is a child of the shell: its PPID is the PID of bash.
Check yourself
You open three terminals and run bash in each. How many bash executables and how many bash processes are there?
From Ready to Done
Process states
Why it matters
Most processes spend their life waiting: for you to type, for the disk, for the network. The state explains why a computer with 300 processes is not slow, and what the R, S and Z in ps mean.
State
Meaning
ps
Ready
has everything it needs, waits for a free processor
R
Running
its code runs; when its time slice ends it goes back to Ready
R
Waiting
waits for an event: disk data, a key, a network packet; it does not use the processor
S
Done
has finished (exit), waits for the parent to read its exit code
Z
$ps-e-o pid,stat,comm PID STAT COMMAND 1 Ss systemd 4100 Ss bash 4210 S sleep 4211 R yes 4213 Sl myapp 4214 Z myapp-worker <defunct> 4220 R+ ps
bash waits for you to type, sleep for its timer; yes computes all the time. The other letters: s session leader, l several threads, + in the foreground.
Check yourself
ps shows S for a text editor you are not typing in. Is something wrong?
fork, exec, exit, wait
Creating a process
Why it matters
Every process except the first one is created by another process. The shell runs each command with the same four calls, so redirects, the PPID and zombies all come from this mechanism.
the parent calls fork: it makes a clone of itself, from now on there are two identical processes
the child calls exec: it replaces its executable with another one (same PID)
the child eventually calls exit (or returns from main) with an exit code
the parent does other work or waits; it calls wait to read the exit code of the child
Check yourself
After fork, which of these is different in the child?
when a parent ends, its children keep running without a parent: they are orphans
the kernel reparents them to init (PID 1): their PPID becomes 1
init calls wait for them when they end
The parent never calls wait
Zombie processes
a process that has finished stays Done until its parent reads its exit code with wait
meanwhile the system keeps its PID and its entry in the process table: allocated, but not used, a 🧟 zombie (Z, <defunct> in ps)
a zombie cannot be killed: it is already dead; only its parent calling wait, or the parent ending, removes it
🐧 + 🧟 = 🛑
Without init there is nobody to adopt orphans and nobody to wait for them: the system would fill with zombies. Linux does not allow it: it panics when init stops.
Check yourself
ps shows hundreds of <defunct> processes with the same PPID. Whom do you fix?
How processes access data
The File Descriptor Table
Why it matters
A process never writes to the display or reads from the keyboard by name: it writes to 1 and reads from 0. The shell decides what those numbers point to, and that is the whole trick behind redirects and pipes.
each process has a File Descriptor Table; every open file has an entry, and the index in the table is the file descriptor
0 (stdin), 1 (stdout) and 2 (stderr) are open from the start; in a terminal all three point to it: the keyboard, the display, the display for errors
a file the process opens goes at the first free index
the table is in the process, the open files are kept by the kernel
The process opens the file by itself
sort opens a file
$cat fruits.txtcherryapplebanana$sort fruits.txt # the file name is an argumentapplebananacherry
the shell starts sort with 0, 1 and 2, and gives it fruits.txt as an argument
sort calls open("fruits.txt"); the kernel places it at the first free index: 3
sort reads the lines from 3, sorts them and writes them to 1; the keyboard (0) is not used
sort fruits.txt · File Descriptor Table
0
stdin
→ keyboard
1
stdout
→ display
2
stderr
→ display
3
opened
→ fruits.txt
Redirect stdin
<: a file instead of the keyboard
A command reads from 0 and writes to 1 and 2. A redirect tells the shell to point one of them to a file, in the child, before it starts the command. The command does not know.
$sort # reads the keyboard, until Ctrl+D$sort < fruits.txt # reads fruits.txtapplebananacherry
Common mistake
sort fruits.txt and sort < fruits.txt are the same
The output is, the mechanism is not. With an argument, sort opens the file itself (at 3) and knows its name; with < the shell opens it at 0 and sort only sees a stream. That is why wc -l fruits.txt prints the name and wc -l < fruits.txt does not.
Instead: use < for commands that only read stdin, or when the name must not appear.
Redirect stdout
> and >>: a file instead of the display
> points 1 to a file and empties it first; >> keeps what is there and writes at the end.
$ls > files.txt # nothing on the display$cat files.txt # files.txt existed before ls ranbackupfiles.txtfruits.txtnotes.txtprojectunsorted.txt$echo one > log.txt # empty the file, then write$echo two >> log.txt # write at the end
> empties the file before the command runs
sort fruits.txt > fruits.txt leaves an empty file: the shell truncates fruits.txt before sort reads it. Write to another file, then rename it.
Redirect stderr
2> and 2>&1: the errors
Errors go to 2, so > alone still shows them. 2> sends them to a file; 2>&1 sends them where 1 points at that moment, so the order of the redirects matters.
$ls /nope 2> errors.txt # nothing shows up$ls /etc /nope > all.txt 2>&1 # both into one file$ls /etc /nope &> all.txt # the same, shorter
All the redirects
Cheat sheet and practice
Redirect
Example
What it does
<
sort < input.txt
stdin from a file
>
ls > files.txt
stdout into a file, emptied first
>>
ls >> files.txt
stdout at the end of a file
2>
ls /nope 2> errors.txt
only the errors into a file
> f 2>&1, &> f
ls /etc /nope &> all.txt
stdout and stderr into the same file
< a > b
sort < unsorted.txt > sorted.txt
both at once
> /dev/null 2>&1
command > /dev/null 2>&1
run silently, discard everything
Heredoc: several lines as stdin
$cat <<EOFHello, world!This is a heredoc example.EOF
The lines up to EOF are sent as they are to stdin; a # there is not a comment. The demo terminal does not do heredocs.
The stdout of one process is the stdin of the next
|: pipe
the shell creates a pipe: a buffer in the kernel with a write end and a read end
it starts ls with the write end at index 1
it starts wc with the read end at index 0
both run at the same time: wc reads what ls writes, until ls ends (end of file)
No temporary file is used. ls prints one name per line when its 1 is not a terminal.
Devices made by the kernel
Special files
🕳️ /dev/null
everything written is discarded; reading gives end of file right away. ls /nope 2> /dev/null hides the error.
0️⃣ /dev/zero
reading gives as many 0 bytes as asked; writes are discarded.
🎲 /dev/urandom
reading gives as many random bytes as asked: keys, passwords, random names.
$xxd-l 8 < /dev/zero # the first 8 bytes00000000: 0000 0000 0000 0000 ........$xxd-l 8 < /dev/urandom # different every time00000000: 9f3a 51c2 07e8 b4d1 .:Q.....$ls-l /dev/null /dev/zero /dev/urandomcrw-rw-rw- 1 root root 1, 3 Oct 12 09:12 /dev/nullcrw-rw-rw- 1 root root 1, 5 Oct 12 09:12 /dev/zerocrw-rw-rw- 1 root root 1, 9 Oct 12 09:12 /dev/urandom
c: character devices, not files: nothing is stored on the disk
1, 3: the driver (major 1) and the device (minor 3) that answer the read
ln -s
A shortcut
Why it matters
Links are everywhere in a Linux system: /bin is a link to /usr/bin on modern distributions, /proc/self is a link, and most configuration of services is turned on by creating one.
ln -s creates a soft link (symbolic link): a shortcut to TARGET
l: the type is link, ls -l shows where it points
the link does not hold the data, it holds a path: its size is 9, the length of notes.txt
the target can be a file or a folder, the path absolute (/usr/share/doc) or relative
Following links
$ln-s shortcut.txt link.txt # a link to a link$cat link.txtbuy milkcall mom$ln-s /usr/share/doc docs$ls docs/ # into the folderbash git
a link can point to another link: the kernel follows them all, until it finds a real file
a link to a folder works like the folder: ls, cd
a loop (a -> b, b -> a) never reaches a file: Too many levels of symbolic links
ls -l, readlink and rm do not follow: they work on the link itself
Where the path starts
Broken links and relative paths
$rm notes.txt # delete the target$ls-l shortcut.txtlrwxrwxrwx 1 student student 9 Oct 12 09:15 shortcut.txt -> notes.txt$cat shortcut.txtcat: shortcut.txt: No such file or directory
deleting the target does not delete the links to it
the link still holds its path, but nothing is there: the link is broken
ln -s does not check that the target exists
A relative target starts from the folder of the link
$cd /home/student$ln-s notes.txt backup/wrong.txt # from backup/$cat backup/wrong.txtcat: backup/wrong.txt: No such file or directory$ln-s ../notes.txt backup/right.txt # go up$cat backup/right.txtbuy milk
Write a relative target as if you were in the folder of the link
Not from your current directory: the kernel resolves the path when the link is used, starting from where the link is.
Moving links
you move
relative link (rel.txt -> notes.txt)
absolute link (abs.txt -> /home/student/project/notes.txt)
the link alone, to another folder
breaks: the path now starts from the new folder
still works
the whole folder, link and target together
still works: they moved together
breaks: it points to the old place
Relative links for files that travel together (a project, an archive); absolute links for files that stay in place (/usr/share/doc, /etc/...).
Check yourself
You run ln -s notes.txt backup/n.txt from your home directory, where notes.txt is. Does cat backup/n.txt work?
Virtual files made by the kernel
/proc: the process file system
/proc
├── 1 systemd
├── 4100 bash
├── 4321 ...
├── self -> the process that reads it
├── cpuinfo
├── meminfo
├── uptime
└── ...
$ls-l /proc/uptime # the size is 0-r--r--r-- 1 root root 0 Oct 12 09:12 /proc/uptime$cat /proc/uptime # but it has contents244699.78 368114.32$readlink /proc/self # the PID of readlink4325
/proc is a virtual file system: every process has a folder named after its PID
nothing is stored on the disk: the kernel writes the contents when a process reads the file
/proc/self is the folder of the process that reads it: ls /proc/self lists the folder of ls
/proc/<PID>
Inside a process
/proc/4321
├── cmdline the arguments
├── comm the name
├── cwd -> the current folder
├── environ the environment variables
├── exe -> the executable file
├── fd/ the File Descriptor Table
├── maps the memory map
└── status PID, PPID, state, ...
$cat /proc/self/statusName: catState: R (running)Pid: 4330PPid: 4100Threads: 1$echo $$ # the PID of the shell4100$ls-l /proc/self/fdlrwx------ 1 student student 64 Oct 12 09:12 0 -> /dev/pts/0lrwx------ 1 student student 64 Oct 12 09:12 1 -> /dev/pts/0lrwx------ 1 student student 64 Oct 12 09:12 2 -> /dev/pts/0lr-x------ 1 student student 64 Oct 12 09:12 3 -> /proc/4331/fd
the PPid of cat is the shell: the shell called fork and exec to start it
0, 1 and 2 point to /dev/pts/0, the terminal: it is both the keyboard and the display
ls opened the folder it lists at the first free index, 3; a redirect changes these links: with > out.txt, 1 points to out.txt
ps, top, pstree and lsof -p PID do not ask the kernel directly: they read/proc; only the owner (or root) can look inside fd/
Quick recap
The ideas, in short
One idea per card; the title is the idea, the text says why it matters in practice. Recap shows all the cards, Flashcard one at a time.
01 · Packages
Software comes from the repository of the distribution
click / Space
01 · Packages
Software comes from the repository of the distribution
The package manager (dnf, apt) downloads checked and signed packages; it needs sudo because it changes the system for everyone.