Walker News

How To Use ps Command To Find Top CPU And Memory Usage Of Processes?

The Linux system is slow because of high CPU utilization and memory is running low? Now, how to use the ps command to find out what are the running processes with top CPU and memory usage?

Well, there are no short of command line tools and GUI programs to find these out. But I think the ps command is one of the top 10 Linux commands and thus believe that most of UNIX/Linux users have came across ps command in the first day of UNIX/Linux introduction class.

But, how many users bother to type man ps and vet through the lengthy manual page for the available option switches?

Customize the ps command output for the subject

I have tested this in RHEL5 Linux command prompt:
ps -eo SFS --sort SFS

where the SFS (short for Standard Format Specifiers) can be one or more of the following keywords. Take note that not all of these SFS are available for sorting, e.g. time.
  • pid to display the process ID of the process.
  • start to display the time of command was started.
  • time is an alias of cputime and is better alternative to bsdtime; to display the cumulative CPU time (user and system) in [dd-]hh:mm:ss format.
  • rss to display the process’s Resident Set Size (RSS) in KB. RSS is regarded as non-swapped physical memory taken by a process.
  • vsz to display virtual memory size of the process in KB, excluding the device mappings.
  • cmd to display the running command or process and its specified arguments.
  • comm to display the running command or process but exclude its specified arguments.

The ps command example

To find out top processes in term of physical memory usage in Linux system, type this:
ps -eo pid,rss,comm --sort rss

As the standard format specifiers time is not available for sorting, it is a bit troublesome if uses ps command to find top CPU usage of processes. E.g. to find Linux processes that use more than 5 minutes of CPU time:
ps -eo pid,time,comm | grep -v 00:0[0-5]

Other than the 7 standard format specifiers mentioned above for used with -o option switch of ps command, there are many more (e.g. cputime, bsdtime, etc) covered in man ps that might be interesting and useful to you.

Custom Search

  1. Amichai S 16-11-11@15:11

    this is really not the tool for this job. ‘top’ is your friend.

2018  •  Privacy Policy