My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Monday, December 7, 2015

ps command #1 - Basic



A linux command to monitor the system process consuming resources on the server. If you are working on a linux system it is good to have at least basic understanding of this command.

ps program or command when run take a snapshot of running processes at that time and display on the terminal which can be used to analyse the system performance or identify any problematic process which can be a risk for system.

ps Command:


When we run simple ps command, it will display very basic information -
$ ps
  PID TTY          TIME CMD
22396 pts/0    00:00:00 su
22402 pts/0    00:00:00 bash
22417 pts/0    00:00:00 su
22420 pts/0    00:00:00 bash
23332 pts/0    00:00:00 ps

PID - process id
TTY - terminal in which process is running
TIME - total cpu time taken till now
CMD - command


Let's try with one argument -f (full)
$ ps -f
UID        PID  PPID  C STIME TTY          TIME CMD
root     22396 22377  0 09:49 pts/0    00:00:00 su
root     22402 22396  0 09:49 pts/0    00:00:00 bash
root     22417 22402  0 09:50 pts/0    00:00:00 su
root     22420 22417  0 09:50 pts/0    00:00:00 bash
root     23337 22420  0 11:02 pts/0    00:00:00 ps -f

this output is display with some more information -
UID - process owner user id 
PPID - parent process id
STIME - process start time


Let's play with some argument and see what will be the output look like -

$ ps -ef
atul      7585     1  0 18:29 ?        00:00:00 /usr/libexec/gvfsd-http --spawner :1.7 /org/gtk/gvfs/exec_spaw/2
root     16991     1  0 Dec04 ?        00:00:00 /usr/sbin/bluetoothd --udev
atul     17099     1  0 Dec04 ?        00:09:26 /usr/lib64/firefox/firefox
atul     22246     1  0 19:28 ?        00:00:05 gnome-terminal
atul     22248 22246  0 19:28 ?        00:00:00 gnome-pty-helper
atul     22377 22246  0 19:35 pts/0    00:00:00 bash
root     22396 22377  0 19:35 pts/0    00:00:00 su
root     22402 22396  0 19:35 pts/0    00:00:00 bash
root     22417 22402  0 19:35 pts/0    00:00:00 su
root     22420 22417  0 19:35 pts/0    00:00:00 bash
atul     22937     1  0 20:06 ?        00:00:00 gedit
root     23282  1899  0 20:47 ?        00:00:00 /usr/libexec/hald-addon-rfkill-killswitch
root     24348  1810  0 22:07 ?        00:00:00 /sbin/dhclient -d -4 -sf /usr/libexec/nm-dhcp-client.action -pf /var/run/dhclient-eth1.pid -lf /var/lib/dhclient/dhclient-e738be73-e337-4f64-865e-aa936ac77c14-eth1.lease -cf /var/run/nm-dhclient-eth1.conf eth1
atul     27098  1236  2 22:23 ?        00:00:00 /usr/lib/rstudio-server/bin/rsession -u atul
root     27112     1  0 22:23 ?        00:00:00 /usr/libexec/fprintd


All process
To see all processes on the system (along with the command line arguments used to start each process) you could use:

$ ps aux


Processes for User
To see all processes for a particular user (along with the command line arguments for each process) you could use:

$ ps U <username> u

$ ps U atul u
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
atul      2695  0.0  0.0 229128   672 ?        Sl   Dec03   0:00 /usr/bin/gnome-keyring-daemon --daemonize --login
atul      2705  0.0  0.1 253264  1888 ?        Ssl  Dec03   0:01 gnome-session
atul      2713  0.0  0.0  20040   128 ?        S    Dec03   0:00 dbus-launch --sh-syntax --exit-with-session
atul      2714  0.0  0.1  32476  1356 ?        Ssl  Dec03   0:01 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
atul      2732  0.0  0.3 133360  3636 ?        S    Dec03   0:06 /usr/libexec/gconfd-2
atul      2740  0.0  0.3 507280  3408 ?        Ssl  Dec03   0:26 /usr/libexec/gnome-settings-daemon
atul      2741  0.0  0.1 286220  1624 ?        Ss   Dec03   0:00 seahorse-daemon
atul      2746  0.0  0.0 137388   844 ?        S    Dec03   0:00 /usr/libexec/gvfsd
atul      2760  0.0  0.5 447048  5116 ?        Sl   Dec03   0:25 metacity
atul      2767  0.0  0.7 502416  7600 ?        Sl   Dec03   0:34 gnome-panel
atul      2769  0.0  0.3 450232  3156 ?        S<sl Dec03   0:35 /usr/bin/pulseaudio --start --log-target=syslog
atul      2772  0.0  0.0  94828   252 ?        S    Dec03   0:00 /usr/libexec/pulse/gconf-helper
atul      2773  0.0  5.6 1199004 57544 ?       Sl   Dec03   1:18 nautilus
atul      2775  0.0  0.0 696412   256 ?        Ssl  Dec03   0:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=18
atul      2778  0.0  0.2  30400  2212 ?        S    Dec03   0:00 /usr/sbin/restorecond -u
atul      2783  0.0  0.4 469076  4244 ?        Sl   Dec03   0:02 gpk-update-icon
atul      2786  0.0  0.0 146404   900 ?        S    Dec03   0:00 /usr/libexec/gvfs-gdu-volume-monitor
atul      2787  0.0  0.2 375072  2924 ?        S    Dec03   0:00 gnome-volume-control-applet
atul      2788  0.0  0.5 331480  5988 ?        S    Dec03   0:48 /usr/libexec/wnck-applet --oaf-activate-iid=OAFIID:GNOME_Wncklet_Factory --oaf-ior-fd=18
atul      2789  0.0  0.2 476996  2900 ?        Sl   Dec03   0:00 /usr/libexec/trashapplet --oaf-activate-iid=OAFIID:GNOME_Panel_TrashApplet_Factory --oaf-ior-fd=24

Process tree
A process tree shows the child/parent relationships between processes. (When a process spawns another process, the spawned is called a child process while the other is the parent)


$ ps afjx





Like the below page to get update  
https://www.facebook.com/datastage4you
https://twitter.com/datagenx
https://plus.google.com/+AtulSingh0/posts
https://groups.google.com/forum/#!forum/datagenx

No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.