Less known Solaris Features: Getting the command line and environment of running processes

There is a really interesting tool to gather informations from a running process. Let´s assume a fellow admin is in her or his well-deserved vacation and now you have to reboot the new machine, because you have to service the memory. Of course you look into the documentation and you find a process that isn´t covered by the documentation and there doesn´t seem to be an startup script or SMF manifest that starts this application. D’oh … yet another last-minute pre-vacation change … shouldn’t happen, but it does happen. Let´s assume you found an process called application in the process list:

bash-3.2# ps -ef | grep "application" | grep -v "grep"
    root 27943 27888   0 23:08:23 pts/1       0:00 /bin/perl ./application --start --debug --foobar=e3421
jmoekamp 27945 27824   0 23:08:28 pts/2       0:00 grep application

You look into the application source code (it´s a perl script, so this isn´t a problem and you see, that the application uses environment variables for config information. Now you have a problem. What are the correct settings of the environment variables? How can you gather the correct information to startup the application again. Solaris can help here with a programm called pargs. At first let´s check the environment of the application first. It´s important to know, that you just can lookup this informations for processes you own. You need to get root privileges to see this information for other processes. Okay, the pargs command offers the -e switch for this task.

# pargs -e 27943
27943:  /bin/perl ./application --start --debug --foobar=e3421
[...]
envp[3]: DATABASEHOST=foobar.server.de
[...]
envp[6]: USERNAME=snafu
[...]
envp[13]: DATABASEDB=importantdatabase
[...]

There is another interesting switch. You can use pargs with the -l switch to get the full command line that was used to start the script, albeit this isn’t that interesting, as you could get similar information with /usr/ucb/ps -auxwwww. But with a known process id pargs is much more comfortable.

# pargs -l 27943
/usr/perl5/5.8.4/bin/perl ./application --start --debug '--foobar=e3421' 

Now you should have all informations to restart the script and -by the way- to update the documentation for the fellow admin.