Pages

Tuesday, 26 May 2020

Day to day linux tools --- monitoring processes with "ps"

1. Basic idea

1.0 "ps" does its job by reading /proc

This means ps doesn't need any privilege to run. Every user can use it.

1.1 "ps" support 3 different schools of options

  • Traditional Unix options, like -p
  • GNU long options, like --pid
  • BSD options, like p
Not all options are available in all kinds, some options may conflict.

1.2 "ps" displays processes based on two criteria

  • What processes to display?  ( rows )
    • all processes: -A or -e
    • select by PID: -p 123,456 
    • select by euid: -u user01,user02
    • select by ruid: -U user01,user02
    • show threads: -T 
  • What properties of a process to display? (cols)
    • full format: -f
    • long format: -l
    • Jobs format: -j
    • user-defined format: -o pid,state,cmd

1.3 Threads are not displayed by default

By default, "ps" only shows the main thread of each process. This is not good in Linux where threads are implemented as processes. The user processes limit "ulimit -u" count threads as processes too.

To list the threads, "-T" option is used. I recommend always use "-T" with ps on Linux.

2. Examples

Traditional Unix options are used in examples here.

# show every process with details
$ ps -Tef

# show vim's processes
$ ps -TC vim

# show processes run by user01
$ ps -Tu user01

# show process whose pid is 20445
$ ps -Tp 20445

# show all processes' tid,pid,ppid,cmd
$ ps -Teo tid,pid,ppid,cmd

No comments:

Post a Comment