What is a Process?
An instance of a program is called a Process. Basically, any command that you give to your Unix – Linux machine starts a new process.The Linux terminal has a number of useful commands that can display running processes, kill them, and change their priority level. This post lists the classic, traditional commands, as well as some more useful, modern ones.
Having multiple processes for the same program is possible.
Types of Processes:
- Foreground Processes: They run on the screen and need input from the user. For example Office Programs
- Background Processes: They run in the background and usually do not need user input. For example Antivirus.
We wrote this tool briefly this post.The top command is the traditional way to view your system’s resource usage and see the processes that are taking up the most system resources. Top displays a list of processes, with the ones using the most CPU at the top.
To exit top or htop, use the Ctrl-C keyboard shortcut. This keyboard shortcut usually kills the currently running process in the terminal.
The ps command lists running processes. The following command lists all processes running on your system:
This may be too many processes to read at one time, so you can pipe the output through the less command to scroll through them at your own pace:
ps -A | less
Press q to exit when you’re done.
You could also pipe the output through grep to search for a specific process without using any other commands. The following command would search for the Watchdog process:
pstree shows running processes as a tree.If you’re using a system which has a lot of users, and you’d like to see who has started a particular script, daemon, or binary, then the pstree utility is very helpful. It draws a tree of all currently running processes – allowing you to see which processes are related.
The kill command can kill a process, given its process ID. You can get this information from the ps -A, top or pgrep commands.
Kill command can send any signal to a process. You can use kill -KILL or kill -9 instead to kill a stubborn process.
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria to stdout.
pkill & killall
The pkill and killall commands can kill a process, given its name. Use either command to kill python:
To change the priority of a process that is already running, use the command
renice.A value of -19 is very high priority, while a value of 19 is very low priority. A value of 0 is the default priority.
Xkill is a utility for forcing the X server to close connections to clients.