Home arrow Journal arrow Today Quick Tip: Use ps command to display useful info about a service
Today Quick Tip: Use ps command to display useful info about a service PDF
Thursday, 12 May 2011
If you build your own daemon and you want to find useful info about your running daemon and processes it spawn use the following ps command:

  ps -o pid,ppid,tty,state,args,wchan

where:
pid - is the (child) process ID of the daemon
ppid - is the parent ID of the daemon
tty - is the tty where the service runs
state - state of the process (for more info man ps)
args - commands and arguments that started that service
wchan - the event on which the process waits (can be pause, select, accept, ttyin ...)

If you want to display info for all services you've started from a terminal use:

  ps -t pts/5 -o pid,ppid,tty,state,args,wchan

where pts/5 is the terminal.

A example run with first command will display:
example 1. Running ps to get detalied info on our running services
machine# ps -t pts/5 -o pid,ppid,tty,state,args,wchan
 PID  PPID TTY      STAT COMMAND          WCHAN
 1160     1 ttyv0    IW   /bin/sh /usr/loc wait 
 1231     1 ttyv0    IWs  login [pam] (log wait 
 2324  1231 ttyv0    IW   -csh (csh)       pause
 2343  2324 ttyv0    IW+  /bin/sh /usr/loc wait
 7265  7264 pts/5    Is   tcsh (csh)       pause
 7288  7265 pts/5    I+   ./daemon_example       accept


Looking at the previous example we want to display only info for daemons started on pts/5 terminal. In that case we run the second example and we get:

example 2. Running ps to get detalied info on our running services
machine# ps -t pts/5 -o pid,ppid,tty,state,args,wchan
  PID  PPID TTY      STAT COMMAND          WCHAN
 7265  7264 pts/5    Is   tcsh (csh)       pause
 7288  7265 pts/5    I+   ./daemon_example       accept
Last Updated ( Thursday, 12 May 2011 )
 
< Prev   Next >

Other BSD Systems

OpenBSD

Misc

Solaris

Polls

Best BSD firewall?