my perl code and the application s/w runs independently
By "independently" I assume that the application is not the parent of your perl code. If that is the case then there is no way to get at the environment variables in an unrelated process on UNIX. The nearest I have come up with is to write a debugger and attach that to the application, but even then you need to know the start address of the environment block, which is harder than it sounds. Parsing memory until you get something that looks like an environment block is possible but not reliable.
If you are on Windows then there is a possible solution with Win32::EnvProcess, but it can be flaky depending on the version of the OS. Let the author know if you decide to take that route.
and inherits its parent ENV variable Do you mean the ENV environment variable? This contains the name of the Korn shell start-up file (typically $HOME/.kshrc). Or do you mean the environment block exposed in Perl as %ENV? | [reply] |
is there a way in perl to get the env variables generated by appln s/w may be by giving porcess ID or appln name?
There's no portable way in *nix period to get the environment of a process other than yourself.
A glance shows some things on CPAN like Shell::GetEnv that may let you run subprocesses and get their info, but I don't know how well that would work with long-running processes, and doesn't help with non-descendant processes anyway.
edit: markup fix
| [reply] |
| [reply] |
FWIW, RHEL 5 should provide the /proc file system. Since you have the PID and (presumably)
sufficient permissions, you could try to read the environment from /proc/PID/environ.
From man 5 proc:
/proc/[pid]/environ
This file contains the environment for the process. The entries are separated by null bytes ('\0'), and
there may be a null byte at the end. Thus, to print out the environment of process 1, you would do:
$ (cat /proc/1/environ; echo) | tr '\000' '\n'
Sorry, no suggestion for the Windows XP part.
Update: It's the environment as seen when the process was invoked.
Changes applied to the environment are not propagated - at least not when I tested it under SuSE 11.1, kernel 2.6.27.7.
| [reply] [d/l] [select] |