Manage the Processes of Linux using ps, pstree, lsof commands

ps (short for “process status”): It Provide the snapshot of the current processes.

pstree: It shows the tree of processes.

lsof: It shows the list of open files, that may be regular file, a directory, a block special file, a character special file,  an  executing  text reference,  a library, a stream or a network file.

1.) Display all processes:

[root@ittroubleshooter ~]#  ps -ef

# ps -aux  (Basically this cmd is used on Unix and BSD OS)

Where, “-f” to display full format listing.
“-e” to display all the processes.
“-a” to display all processes for all users.
“-u” to display  process’s user/owner.
“-x” to display processes not attached to a terminal.
2.) List the Process based on the User or UID:
 [root@ittroubleshooter ~]#ps -f -u sftp,btctomcat

Where, “-u” to displays the process that belongs to a specific username.

“-f” to display full format listing.

Note: Tomcat and Ftp both are system users.

3.) Display particular process:
  [root@ittroubleshooter ~]# ps -f -C btctomcat

Where, “-C” to displays processes whose executable name is given in command list.

4.) Display elapsed wall time for processes.(Tricky Command):
  [root@ittroubleshooter ~]#  ps -p 12150 -o pid,etime,pcpu=

PID         ELAPSED   %CPU
12150       00:39      0.4

Note: Results shows the process 12150 running for 39 sec. and using 0.4% cpu utilization.

Where, “-o” to displays  Specify user-defined format.

“-p” is a process id.

5.) Sort five process utilizes more cpu usage.(Tricky Command):
 [root@ittroubleshooter ~]# ps aux --sort=-pcpu | head -5

Where, “-” or “+” symbol indicating descending or ascending sort respectively.

“-a” to display all processes for all users.

“-u” to display  process’s user/owner.

“-x” to display processes not attached to a terminal.
6.)  Display Process tree based on PPID(Parent Process Id):
[root@ittroubleshooter ~]# pstree -p <PPID>

Note: This command display all Child process against the PPID. Using “ps  -f -C <command>” Cmd We get the PPID of the particular process.

Where, “-p” to display the PID of process.

Note: If this pstree command is not work .Please install psmisc package on the system.

7.) Display Command Line Arguments:
[root@ittroubleshooter ~]#  pstree -a -p gaurav


Where, “-a” to display the command line arguments associated with a particular process.

8.) List all Open Files with lsof Command:
[root@ittroubleshooter ~]# lsof | grep oracle | wc -l


Showing Count of open files against particular service or command.

9.) List User Specific Opened Files:
[root@ittroubleshooter ~]#lsof -u btctomcat

#lsof -u <User_name>

10.) Opened files based on process names:
[root@ittroubleshooter ~]# lsof -c btctomcat

#lsof -c <process_name>

11.) Lists of open files by PID.:
[root@ittroubleshooter ~]# lsof -p 11262

#lsof -p <PID>

12.) Opened files in a directory:
[root@ittroubleshooter ~]# lsof +D /var/ftp/

#lsof +D path_of_the_directory


bash    11262   gaurav  cwd    DIR  253,0       16  153 /var/ftp

Leave a Reply

Be the First to Comment!

Notify of