Is there a way to read environment variables of other processes using Perl and in a Linux or Solaris environment?

jac_no_k picture jac_no_k · Feb 6, 2009 · Viewed 17.4k times · Source

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?

Answer

In linux it looks like the /proc/<pid>/environ psuedofiles contain the environ variable passed when the process was created. If you have sufficient permission, you can read those.

They do not appear to track changes in the processes environment after launch.

That suggests that you would have to disect the processes memory dump to get what you're asking for.

Tricky.