Process(ps) cmd in linux

June 11, 2019

fork vs exec

fork creates child process and returns child’s pid

child process gets zero as returned value from fork.

list by user

$ ps -u $USER

Ref: https://fedoramagazine.org/inspect-manage-processes-ps/

list processes by group


$ ps -G groupname1 groupname2
e.g.
$ ps -G root

Inverse selection (Using -N option)

Select all the process those not started by root(group);

$ ps -u root -N

Note: htop or top to see how much cpu, ram used for the processes


Process states

Process filters

ps -C firefox -L -o pid,tid,pcpu,state,nlwp,cmd 

Sort output

$ ps -eF --sort -rss

process tree

--- display process tree of current user processes
$ ps f


-- display process tree of all user processes
$ ps -e f

Note: htop can be used to view process tree as well.

Find out thread details of a process

$ ps -p <PID> -T -o pid,tid

  PID   TID
 3926  3926
 3927  3927
 4602  4602
 
(OR)

$ ps -p <PID> -L -o pid,lwp
 
  PID   LWP
 3926  3926
 3927  3927
 4602  4602
 

pkill command

$ pkill <pattern>

-- display count of matching processes and kill
$ pkill -c <pattern>