🌐 🇵🇱 Polski · 🇬🇧 EN
Whenever a program is launched or a command is issued in the system, a process is created for it. Such a process has a unique identifier (PID) so that it can be located. System processes are a critical issue from the point of view of maintaining the environment and providing services to system users and clients. Process management will help maintain a stable environment and assist when operations become unstable. Commands applicable to process management in the system:
- ps - Information about running processes
- kill - Terminate a process (kill it)
- pgrep - Search for a process by PID
- pidof - Display all processes of a given service or command
- top - Monitor system resources
- renice - Set process priority
To start, let's see which processes the root user has running
# ps
PID TTY TIME CMD
4474 pts/3 00:00:00 bash
4506 pts/3 00:00:00 ps
The ps command has many options for formatting and obtaining various results regarding processes, and to see additional, more detailed information, we can use the "-u" switch.
# ps u
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2387 0.0 0.1 1660 424 tty1 Ss+ 07:30 0:00 /sbin/mingetty tty1
root 2388 0.0 0.1 1660 420 tty2 Ss+ 07:30 0:00 /sbin/mingetty tty2
root 2389 0.0 0.1 1660 420 tty3 Ss+ 07:30 0:00 /sbin/mingetty tty3
root 2390 0.0 0.1 1660 420 tty4 Ss+ 07:30 0:00 /sbin/mingetty tty4
root 2391 0.0 0.1 1660 448 tty5 Ss+ 07:30 0:00 /sbin/mingetty tty5
root 2392 0.0 0.1 1660 420 tty6 Ss+ 07:30 0:00 /sbin/mingetty tty6
Now, besides the PID, you can also see memory and CPU usage. It is also good practice to use combinations of switches and utilize "grep" to obtain filtered information about what is currently of interest.
# ps aux | grep ssh
root 4286 0.0 0.1 62616 1216 ? Ss Sep23 0:00 /usr/sbin/sshd
root 15872 0.0 0.3 90116 3248 ? Ss 10:06 0:00 sshd: user01 [priv]
user01 15874 0.0 0.1 90116 1740 ? S 10:06 0:00 sshd: user01@pts/0
user01 15921 0.0 0.0 61176 728 pts/0 R+ 10:14 0:00 grep ssh
The full capabilities of the ps command can be explored by typing:
$ ps - help
Knowing the ps command and how to manipulate its switches will enable you to solve many problems you will encounter on the RedHat exam, and it is a great help in real-world system administration.
What happens if one of the processes running in the system becomes unresponsive? In such a case, you can use the "kill" command, which will terminate its operation. We always use the "kill" command when a service process is not responding and it is already known that such a service needs to be restarted.
Kill command syntax: # kill PID
If you want to stop the SSH service because it is not working correctly, you need to find its PID and then terminate it with the "kill" command. If we see that the PID for SSH is 4125, the command to remove the process is:
# kill 4125
Sometimes even the "kill" command may not be able to shut down a process, and in such a case, you can use the -9 switch — this option gives the system a higher priority.
# kill -9 4125
What to do if we don't know the PID of the process we want to shut down? Searching for a process PID can be done using the "ps" command with additional switches and "grep" filtering. If that is not enough, we can try using two other commands: pidof and pgrep.
Let's see pidof in action, where we use the service or daemon name as the search term. So, to find the SSH service process, we do:
# pidof sshd
15874 15872 4286
If we want the result in an easier-to-read format, the following works well:
# pgrep sshd
4286
15872
15874
It is good to know how to find a specific process you want to shut down and how to search for it among a multitude of other processes, but what if we need to know more about a process, e.g., how much memory and CPU power it consumes? Let's get to know the "top" command. This command provides detailed information about processes, including resource usage for a given process.
To exit the TOP view, press the "q" key.
To achieve greater comfort in system operation, it is possible to configure process importance by assigning them priorities. The "renice" command, which assigns CPU priority, is used for this.
Renice command syntax: # renice <priority> [options]
Renice command options:
- -p PID - Change priority for a process with a given PID
- -u user - Change priority for processes of a given user
Priority values range from -20 to 20. Only root user processes have a priority of 0. To change the priority of a selected process, we execute:
# renice -2 3874
This command will change the priority of the service with PID 3874 to a better one. Knowing the subject of processes will allow you to become a better administrator, and these skills will allow you to find, diagnose, and fix emerging problems faster.

Comments