Well, we know that command ‘ps –aux’ will show all the processes currently running on the system. We can sort the output of this command by using sort command piped after ps. We discussed about sort command before, you might want to have a look at it here. Lets first check the output of ps –aux command as follows:
linux:~ # ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 588 244 ? S Feb17 0:04 init [5]
root 2 0.0 0.0 0 0 ? S Feb17 0:00 [migration/0]
root 3 0.0 0.0 0 0 ? SN Feb17 0:00 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S Feb17 0:00 [migration/1]
root 5 0.0 0.0 0 0 ? SN Feb17 0:00 [ksoftirqd/1]
root 6 0.0 0.0 0 0 ? S< Feb17 0:00 [events/0]
root 7 0.0 0.0 0 0 ? S< Feb17 0:00 [events/1]
root 8 0.0 0.0 0 0 ? S< Feb17 0:00 [kacpid]
root 9 0.0 0.0 0 0 ? S< Feb17 0:00 [kblockd/0]
root 10 0.0 0.0 0 0 ? S< Feb17 0:00 [kblockd/1]
root 11 0.0 0.0 0 0 ? S Feb17 0:00 [kirqd]
[output cut]
As you can see, there are lots of processes. Lets sort the output and determine which processes are taking most of my system memory.
linux:~ # ps aux| sort -k4 -r| head -5
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 3117 0.0 3.0 31084 22512 ? S Feb17 0:02 kdeinit: konqueror –preload
root 3146 0.0 2.1 27296 16060 ? S Feb17 0:05 kdeinit: konsole
root 3190 0.0 2.1 26824 15608 ? S Feb17 0:01 kdeinit: konsole
root 3106 0.0 2.1 26760 15724 ? S Feb17 0:02 kdeinit: kicker
linux:~ #
With the sort command piped to the output of process command, we have successfully sorted the processes with respect to their memory usage. This way, we can easily find the culprit process without a need to look through all the running processes.
Adnan Khurshid
Adnan Khurshid, the author of this article, has been working in a telecommunication sector since 2007. He has worked there as a VAS (Value Added Services) engineer and has excelled remarkably in the field. Working in this field has been his passion and he has always made efforts to keep himself up to date. Find more about him on LinkedIn
Tags: cpu usage, memory usage, ps -aux, sort cpu usage, sort memory usage