Using the 'ps' command to troubleshoot your website

There are several commands you can run to troubleshoot your server. These commands must be ran in a terminal after logging into the server via SSH. View the following article for further details:

The 'ps' command

One command you could use to troubleshoot is ps. The ps command helps you keep track of your Memory and CPU usage.

For example, if you're using a VPS machine and start to notice that your memory usage went from 60MB to 250MB a day, you should probably take a close look at what is going on behind the scenes.

The following describes various commands that help you pin point high memory usage and high CPU usage.

The following commands must be ran within a shell terminal. View the SSH article for further details.

Displaying the top ten processes

The following four commands display the top ten (10) processes that are using memory:

[server]$ ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10
[server]$ ps -eo pcpu,pid,user,args | sort -r -k1 | less
[server]$ ps -eo pmem,pid,user,args | sort -k 1 -r | head -10
[server]$ ps -eo pmem,pid,user,args | sort -r -k1 | less

The following command shows USERNAME, CPU%, MEMORY%, and the number of processes running. Run this command on a single line:

[server]$ ps aux | awk '{cpu[$1]+=$3; mem[$1]+=$4; procs[$1]+=1} END { for (user in cpu){ print user,"cpu:",cpu[user],"mem:",mem[user],"proc:",procs[user] } }'

Displaying memory usage with /proc/meminfo

[server]$ ps aux --sort pmem

Use the following command to view memory usage over time (requires you to repeat the command or usage of a cron job):

[server]$ ps ev --pid=[EnterPID]

To display all currently running processes and detailed information, use the following command:

[server]$ ps -ef

and on most systems:

[server]$ ps -aux

You can find a memory leak by running:

[server]$ ps ev --pid=[HighestEnterPID]

See also

Did this article answer your questions?

Article last updated .