If you are on Windows 10 or 11:
If you have a Ubuntu on WSL installed directly jump to the next step. If not, install Ubuntu on WSL using the guide here.
Open Ubuntu on WSL and enter the following command.
A process is the instance of a computer program that is executed by one or many threads. Processes
have a parent-child relationship, meaning one process gives rise to another. Each process has an
unique process ID or PID.
The types of processes are:
Init Process – This is the first process that is started when the compter is booted. It’s PID is
1.
Parent Process – A parent process gives rise to other processes.
Child Process – A child process is initiated by a parent process.
Interactive Process – Also known as foreground process, it usually is interacting with the
user and is in kernel mode.
Background Process – Also known as a Daemon. It runs silently in the background.
Zombie Process – This process is supposed to have been terminated by the exit system call
but is still present on the process table.
Orphan Process – This process is a child process whose parent process has been terminated
by the exit system call.
Reading process information
The ps command shows the snapshot of the current processes running on the system with their
PIDs. Here there is a field called STAT which shows the process status.
We will use ps -ef where the ‘e’ flag directs to show the processes started by other users too and ‘f’
flag stands for full.
Here there is a field called STAT which shows the process status. The different forms include:
R: Running
T: Terminated
S: Interruptible sleep
For finding a process in the list, use the grep command.
It is to be remembered that in UNIX based operating systems, everything is treated a file or a
directory. Including processes. Hence, another way to view all processes can be viewing the
directory which stores the processes as files or subdirectories. (This directory is virtual and doe not
reside on the disk). The directory is ‘/proc’ and to view the contents, we can simply run
ls -l /proc
It is to be noted that here, each process is represented as a directory and the resources it is using as
subdirectories. Hence, you can ‘cd’ into a process and ‘ls’ the contents. Otherwise, if you have ‘tree’
installed, you can see the directory structure of the the directory by running
tree /proc
Each process directory has a file inside with the name ‘status’ that contains the current status of the
file. To view the status of a process, run
cat /proc/<PID>/status
Run Command
/proc/
/status
Signals
There are a lot of signals that we can send the processes. These signals are labelled with the names
starting with SIG. For example, the SIGTERM. In linux, we can terminate a process by sending it
the SIGTERM signal by pressing Ctrl+C key combination.
Signals:
SIGTERM signal allows the process to clean up and close the resources it was using before
being terminated.
SIGKILL signal, on the other hand, does not give the process time to clean up the resources.
This may result in file or resource corruption in case a resource is not closed properly
SIGSTP signal puts a process in a suspended state. (Ctrl+Z key combination also sends this.)
SIGCONT signal resumes a process in suspended state to running state.
Process management
To kill a process, we use the kill command. This sends a SIGTERM signal to the process
kill <PID>
However, we can use the ‘KILL’ flag to send a SIGKILL signal as well. However, this should be the
last resort to killing a process.
kill -KILL <PID>
Similarly, to put a process to suspended state, we need the SIGSTP signal. This can be done by
using the ‘TSTP’ flag with kill command.
kill -TSTP <PID>
To resume a suspended process, we need the SIGCONT signal. This can be done by using the
‘CONT’ flag with kill command.
kill -CONT <PID>
The results of these commands can be seen by viewing the process table with ps -ef command.
Run Command
Resource Monitoring
The command to see the system utilization in real time is the ‘top’ command.
The ‘uptime’ command gives information about the current time, how long the machine is running,
number of users logged in and the load average. The load average is in 1, 5 and 15 minutes interval.
The ‘lsof’ command lists open files and what processes are using them.