In Perl, I need to read the environment of other processes.
- The script is running with root privileges.
- The script will be running in both Linux and Solaris.
- I would like a solution that’s mostly platform agnostic, at least between Linux and Solaris. In Linux, examining the /env/<proc_id>/environ can get me the answer.
- I would like to avoid having to fork. I already have a solution forking ‘/usr/ucb/ps -auxwwwe $pid’
Any ideas?
For Solaris, you could try the procfs module from CPAN. Even though this module still seems quite young, this quote sounds hopeful:
I imagine that this is probably just the initial environment (just like the
environfile under linux), but that seems to be what you want?Otherwise, although I see you say you don’t want to fork, a simple solution would probably to crank ~20 lines of C to produce a small program that just spits out the environment on Solaris as the exact equivalent of the Linux
environfile. I have something very similar in C already. If you’re interested, I can post it.EDIT (after reading OpenSolaris pargs.c): The environment buffer is reallocated under Solaris when the environment changes, so the psinfo pointer may be invalid. For a bullet proof solution, you need to hunt down _environ. That’s all probably more hassle than you need…
pargs -e <pid>might be a nicer alterative to UCBps(1)if you do go the fork route, though.