Report information of processes: zero to hero

Dejanu Alex
3 min readApr 29, 2020

--

Detailed information about processes, which one would choose ?

  • $ ps aux
  • $ ps -aux
  • $ ps -ef
man ps

Thus, “ps -aux” will fail (unless you want to know about user “x”). As a convenience, however, “ps aux” still works as it did in Tiger.

ps (process status) accepts several kinds of option

  1. Unix options: which must be preceded by and may be grouped
  2. BSD options: which must not be preceded by and may be grouped
  3. GNU-style long options: each of which must be preceded by --

Coming back to the original question:

Go for *BSD-style approach and display all processes of all users and also lift the BSD-style “must have a tty” restriction

$ ps auxf just throw an f in order to see the ancestry tree

  • when you want : VSZ (virtual memory size of the process [KiB]), RSS(resident set size, the non-swapped physical memory that a task has used) and %CPU (cpu utilisation of the process)
ps aux

Or you can go for *UNIX-style approach and display all processes (daemons to) using BSD long format with full listing

$ ps -elf

ps -ef
ps -elf
  • when you want :PPID(parent process ID), NI(nice value), C(processor utilisation)

Go even further, customise your output:

Specified user-defined format, e.g. PPID, PID, Elapsed time, Percentage Memory Usage, : $ ps e -o ppid,pid,etime,command,pmem,cpu

ps e -o ppid,etime,command,pmem,cpu

Or you can add columns besides the default ones e.g: Elapsed time and ratio of the process’s resident set size to the physical memory on the machine:

$ ps -ef -O etime,pmem,command

ps -ef -O etime,pmem,command

Now let’s put it to work:

  1. List processes of a certain user: $ ps -u <user_name> (user ID or user name)
  2. List all processes by executable name: $ ps -C <executable_name>
by executable name

3. Sort the output of ps based on memory usage: $ ps aux --sort=-%mem

4. Get the PID of the current process: $ echo $$

5. List open files by a process: $ lsof -p <PID>

files open by vim

6. Determine which process (PID) has open a file: $ fuser <file> or $ lsof -t <file>

Sources:

--

--

Dejanu Alex
Dejanu Alex

Written by Dejanu Alex

Seasoned DevOps engineer — Jack of all trades master of None

No responses yet