• Each process has its own PID (process ID) but there is an exception. For example, you can find two PID 1 if you use virtualization
• PID 1 is always “init”, run at boot
• All processes except init are created by other process

ps aux                  # To see all processes running in the system
ps aux | grep init

# Display processes
# or
htop                    # recommended but need to install

• PID 1 is always “init”, run at boot
• Init is the parent of all processes

ps aux | grep init

UID identifies who own the process
EUID (effective uid) is a way to give a user, other than the one who owns the process to spawn the process
• If you have a low priority task, you set the niceness high


Process SIgnals

• The way that a process communicates
• Sent by the kernel when the process did something bad like division by zero or when someting is ready
• Signals are sent to parent process(es) and the kernel
Standard Signals (man 7 signal)
◇ SIGTERM (15): terminate (default)
◇ SIGKILL (9): kill

# List of signals
kill -l

# Terminate a process
# For example firefox
ps aux | grep firefox
kill 15 2196            # 15 = terminate (default), 2196 = pid
# or
kill 2196

# Kill a process
kill 9 2196             # last resort. may lead to corrupted data

# Kill all processes by process name
ps aux | grep cups      # cups = Common Unix Printing System
sudo killall cupsd

# Kill all processes run by username
sudo pkill -u username

# References
man pgrep
man pkill
man 7 signal



• There are 4 states that a process can be in:
◇ runnable
◇ sleeping
◇ zombie
▪ something that has finished and waiting to exit
▪ If there are too many zombies, check if parent process is frozen
◇ stopped
▪ something that is stopped by SIGSTOP and waiting for a SIGCONT to continue



• To find the niceness of a process, look at 4th column (NI) in htop
• The higher the number, the lower the priority
• Range: -20 to 19 (default = 0)

# Launch a process with nice
nice -n 15 /backup/not/important/at/all/task

# Change the niceness of a process
# -5: niceness, 2744: pid
sudo renice -5 2744

• You can also change niceness of a process directly in htop by pressing F7 or F8


The /proc Filesystem

• Proc is a virtual file system and is mounted on /proc

# List of all processes
ls -alh /proc

# List of init process
sudo ls -alh /proc/1/ | less

• Notice the size of init process is 0 because they are read and executed on the fly

sudo -i

# How the process is called
cat cmdline

# Reference
man strace