Friday Oct 15, 2010

Associating a PID with a Service

The question of how to associate a process id with a SMF service recently came across an internal alias and I thought it was worth sharing.

Take this generic looking Java process:

bleonard@opensolaris:/system$ ps -fp 949
     UID   PID  PPID   C    STIME TTY         TIME CMD
    root   949   947   0   Oct 11 ?           3:46 /usr/jdk/jdk1.6.0_13/bin/java -Xms4M -Xmx128M -Dcom.sun.management.jmxremote -D

If I'd like to trace back to which SMF service started this process, I start by getting the process' contract ID:

bleonard@opensolaris:/system$ ps -o ctid -p 949
 CTID
   59

I can then use the ctstat command to cross reference the contract ID to the SMF service:

bleonard@opensolaris:/system$ ctstat -vi 59
CTID    ZONEID  TYPE    STATE   HOLDER  EVENTS  QTIME   NTIME   
59      0       process owned   7       0       -       -       
	cookie:                0x20
	informative event set: none
	critical event set:    core signal hwerr empty
	fatal event set:       none
	parameter set:         inherit regent
	member processes:      947 949
	inherited contracts:   none
	service fmri:          svc:/application/management/common-agent-container-1:default
	service fmri ctid:     59
	creator:               svc.startd
	aux:                   start

And just to go full circle:

bleonard@opensolaris:/system$ svcs -lp  common-agent-container-1
fmri         svc:/application/management/common-agent-container-1:default
name         Cacao, a common Java container for JDMK/JMX based management solution
enabled      true
state        online
next_state   none
state_time   Mon Oct 11 12:54:59 2010
logfile      /var/svc/log/application-management-common-agent-container-1:default.log
restarter    svc:/system/svc/restarter:default
contract_id  59 
dependency   require_all/none svc:/system/filesystem/local (online)
dependency   require_all/none svc:/network/initial (online)
process      947 /usr/lib/cacao/lib/tools/launch -w /var/run/cacao/instances/default/run -L 1638
process      949 /usr/jdk/jdk1.6.0_13/bin/java -Xms4M -Xmx128M -Dcom.sun.management.jmxremote -D

For a nice little tutorial on contracts, check out this Contract Subsystem Lab.

Wednesday Sep 29, 2010

ps tip

I often use the ps -ef command when looking for a running process. However, sometimes I'm frustrated by the fact that ps truncates the the CMD output. As an example:

bleonard@opensolaris:~$ ps -ef | grep evolution-data
bleonard 15803     1   0   Sep 27 ?           0:00 /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-i

In a recent opensolaris-help forum post, Mike Meyer provided some undocumented BSD compatible options to get more details:

I habitually use "ps auxww" (note no "-" - bsd ps doesn't require it, and that triggers the BSD mode of /usr/bin/ps), which is all processes (ax) in a "user" (u) format. No w option truncates each line at 80 characters, one w option truncates each line at 132 characters, and two w options doesn't truncate it at all.

So, for my example:

bleonard@opensolaris:~$ ps auxww | grep evolution-data
bleonard 15803  0.0  0.22351610840 ?        S   Sep 27  0:00 /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2 --oaf-ior-fd=28

Of course, as it was also pointed out, once you know the process id you can get the same argument information, in a more readable format using, the pargs command:

bleonard@opensolaris:~$ pargs 15803
15803:	/usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-ii
argv[0]: /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24
argv[1]: --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2
argv[2]: --oaf-ior-fd=28

Or, in single line as pointed out in the comments below:

bleonard@opensolaris:~$ pgrep evolution-data | xargs pargs 
15803:	/usr/lib/evolution-data-server-1.2/evolution-data-server-2.24 --oaf-activate-ii
argv[0]: /usr/lib/evolution-data-server-1.2/evolution-data-server-2.24
argv[1]: --oaf-activate-iid=OAFIID:GNOME_Evolution_DataServer_CalFactory:1.2
argv[2]: --oaf-ior-fd=28
 
About

The Observatory is a blog for users of Oracle Solaris. Tune in here for tips, tricks and more as we explore the Solaris operating system from Oracle.

Connect with Oracle Solaris:


Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
20
21
22
23
24
25
26
27
28
29
30
   
       
Today