System Monitoring

Monitor and terminate processes

View running processes

On Linux, the ps command is used to print a list of actively running processes. To show all processes, use the a and x options: ps ax.

Another useful option is u. It adds additional info to the output, like CPU and memory usage for each process:

        $ ps axu
        
          
            USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
          
            mauritz     2872  5.0  1.8 8654180 612260 ?      Sl   04:33   2:02 /app/zen/zen
          
        
      

However, the output also contains a bunch of columns you might not find very useful. You can instead explicitly specify what columns you want:

        $ ps ax -o user,pid,%cpu,%mem,cmd
        
          
            USER         PID %CPU %MEM CMD
          
            mauritz     2872  5.8  2.0 /app/zen/zen
          
        
      

To make it easier to find relevant processes, add --sort %cpu or --sort %mem to list processes in increasing order of CPU and memory usage respectively.

If you are looking for a specific application, use grep to search for it in the output:

        $ ps ax | grep zen
        
      

Lists running Zen processes

Terminate processes

Sometimes an application becomes unresponsive, in which case you might have to terminate it. The pkill command exists for exactly this purpose.

If you've used ps to locate the process you want to terminate, specify the PID:

        $ pkill 2872
        
      

Terminates the process with PID 2872

However, in most cases a running application consists of multiple processes. To terminate all of them, specify the name of the application instead:

        $ pkill zen
        
      

Terminates the Zen application

By default, processes will be terminated gracefully, which does not always work when they're unresponsive. To forcefully terminate a process, use the -9 flag:

        $ pkill -9 2872
        
      

Be careful! You might lose data, only do this as a last resort.