Table of contents
Process in Linux is nothing more than a piece of code or program in execution. It's a running instance of a program. Except for the init process, every process is run by another process. A process running another one is called the parent process.
ps command
To show the processes that are running in the current session:
ps
To show more details:
ps -u
- A few more properties that we can't pass by:
USER - Username of the process owner.TTY - terminal typeTIME+ - total time the process has been runningCMD - name of the command that launches the process%CPU - Percentage of CPU used by the process%MEM - Percentage of RAM used by the processS - state of the processD - uninterruptible sleepR - runningS - sleepingT - traced or stoppedZ - zombie
To display a list of all running processes:
ps aux
In the image above, you can see the
To find a process by PID:
ps -f 1
In this case, we're looking for the init process run by the Linux kernel.
The init process might have different names, for example,
It has
top command
There is another program that shows the processes. Its name is
If you don't like the
What happens when we run the command in the terminal
Suppose we run
The command invocation will consist of the following steps:
- It forks into two processes
- The copy of itself is replaced with
sleep 1 command execution - When the copy is done with execution, it returns control to the parent process
Here is a diagram:
Suspending the process
Until the copy of the command didn't finish, the execution control won't be returned to the parent process.
You can run
From this point, we can try to suspend the process by pressing
Now if we run
Another way to suspend is to run command with
For example:
sleep 300 &
This will run
jobs command
It display status of jobs in the current session.
We'll need this to display suspended processes.
jobs
To display additional information such as
jobs -l
Foreground the process
To foreground the process:
fg %1
Killing the process
Before we understand how to interrupt or kill the processes, we must understand the signals.
Signals are event notifications that are sent to processes mainly to terminate, interrupt, kill, or suspend the processes.
To read more about the signals, you can visit Linux manual page.
To display a list of signals in your terminal run:
kill -l
To terminate the process in the most common way, use
kill -15 4664
- Here are a few more signals that you've probably used before:
Ctrl+z - sendsSIGTSTP Ctrl+c - sendsSIGINT Ctrl+<md-code> - sends SIGQUIT
Signals are a sort of contract to the process. Thus, it doesn't mean that if you send a
kill -9 4664