If you are interested in finding out which process is consuming most of your system resources i.e. CPU cycles or memory, then read on.
In Linux you can view the top 10 memory consuming processes by using certain ps command options. Let’s see how.
For those who are too eager, here are the quick and readymade commands:
Top 10 memory consuming processes
Top 10 process according to CPU load
How it Works
It is very interesting to know how these commands actually work. Let’s see it here.
To see every process in your system you can use the command
To see every process with a user-defined format:
The output will look like
Ss root root 0.0 0 1 0.0 init
S< root root 0.0 1 2 0.0 migration/0
SN root root 0.0 1 3 0.0 ksoftirqd/0
S< root root 0.0 1 4 0.0 watchdog/0
S< root root 0.0 1 5 0.0 migration/1
SN root root 0.0 1 6 0.0 ksoftirqd/1
S< root root 0.0 1 7 0.0 watchdog/1
S< root root 0.0 1 8 0.0 migration/2
SN root root 0.0 1 9 0.0 ksoftirqd/2
The option ax causes to list all the process while the o option requires a user defined format to display in the output of the command
It accepts certain keywords as STANDARD FORMAT SPECIFIERS. Some of the useful formats are
euser – > Effective User ID.
stat – > Process State Descriptor
ruser – > Real User ID.
pmem – > percentage of Memory consumed
ppid – > Parent Process ID
pid – > Process ID
pcpu – > Percentage of CPU
comm – > command or the process name.
For an extended list of Format Specifiers, you can refer to the manual of ps command
The format descriptors pcpu and pmem are useful to us.
%CPU %MEM COMMAND
0.0 0.0 init
0.0 0.0 migration/0
0.0 0.0 ksoftirqd/0
0.0 0.0 watchdog/0
0.0 0.0 migration/1
0.0 0.0 ksoftirqd/1
0.0 0.0 watchdog/1
0.0 0.0 migration/2
0.0 0.0 ksoftirqd/2
Top 10 Memory consuming process
The command is
1.8 mysqld 12406 mysql
1.7 java 21933 acladmin
0.2 puplet 21489 root
0.1 yum-updatesd 11599 root
0.1 nautilus 21462 root
We displayed the percentage of Memory consumption in the first field. That formed the input of the sort command which sorted the first columns according to number and then we displayed only the 5 process from the top using head.
Top 10 CPU consuming process
The command is
4.3 cmanicd 8491 root
2.2 java 21933 acladmin
0.6 unicelpush1sc 14236 acladmin
0.4 unicelpush1ss 14527 acladmin
0.3 snmpd 7036 root
We used the same trick here but the pcpu specifier is used instead of the pmem which displays the percentage CPU utilization.
After knowing the culprit process you might want to kill the process by sending signals. Check out how to send signals to process using kill command.