Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

how do i get the environment variables of a proces?

Highlighted
Occasional Visitor

how do i get the environment variables of a proces?

I am porting a perl script to hpux and I need a way to get the environment variables of a certain process. To do that in linux I look at /proc//environ. How do I do that on hpux?
14 REPLIES
Acclaimed Contributor Acclaimed Contributor

Re: how do i get the environment variables of a proces?

Hi:

# perl -le 'for $key (keys %ENV) {print "$key=$ENV{$key}"}'

Regards!

...JRF...
Occasional Visitor

Re: how do i get the environment variables of a proces?

That will give me the env variables of MY process. I want to get them for any process give the PID of the process.
Acclaimed Contributor Acclaimed Contributor

Re: how do i get the environment variables of a proces?

Congratulations, you have created a non-portable application. There is no equivalent of the /proc filesystem in HP-UX at 11iv2 and below. In principle, you could do this by attaching gdb to a running process but that's not a very portable solution as well.
If it ain't broke, I can fix that.
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

As mentioned, there is no easy way to do this.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

So now that we know that the immediate question has no easy answer, and probably required excesive (unsafe) priv on Linux, maybe it is time to focus on...

What is the real problem you are trying to solve?

When you get those ENV variables... what do yo intent to do with them?
Maybe there is a better way than looking over the process shoulder. Maybe you can one can ask nicely.

Cheers,
Hein.


Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

Hein,

Just for clarity there is no excesive (unsafe) priv on Linux for accessing info via procfs. it's a pseudo filesystem and is used exactly for the purpose(s) that Naoum used it.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

Hmm, how can one create a truly secure environment if one process can freely communicate with an other? Never mind... Hein

Acclaimed Contributor Acclaimed Contributor

Re: how do i get the environment variables of a proces?

A similar question was asked about ps -eew, which also doesn't exist on HP-UX:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1109088
Occasional Visitor

Re: how do i get the environment variables of a proces?

The application was looking for the ORACLE_HOME of the process ... I guess I'll rewrite it to use the path to the executable out of ps -ef or something like that.
Thanks a lot guys.
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

Maybe not quite what you miss,
but how about parsing the listener process from the proc table.
Most of the times it should enclose the ORACLE_HOME up to bin in its (ps) args.

e.g.

# UNIX95= ps -u oracle -x -o args|grep tns
/app/oracle/product/9.2.0/bin/tnslsnr l_alma -inherit

@Hein "how can one create a truly secure environment?"

The Linux folks have come up with an abundance of possible solutions.
To name but a few

SELinux, AppArmor, VServer, Xen, User Mode Linux

or from BSD take jails etc., etc.

The /proc filesystem is a true boon that on Linux'es that don't use any of the above separations or mandatory access controls
that I sometimes miss on HP-UX.

Madness, thy name is system administration
Occasional Visitor

Re: how do i get the environment variables of a proces?

Ralph, that's exactly what i meant. thanks.
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

Hein, Ralph, Court:

In Linux, much detailed information is available at /proc// virtual directories... but the security-sensitive information is protected so that you must be the owner of the process (or root, of course) to be able to read it. This protection is achieved through traditional unix filesystem permissions.

In particular, the environment file /proc//environ is protected:
$ ls -l /proc/1/environ
-r-------- 1 root root 0 2007-04-11 17:52 /proc/1/environ
$ ls -l /proc/11882/environ
-r-------- 1 mkurkela mkurkela 0 2007-04-11 17:56 /proc/11882/environ
$ cat /proc/1/environ
cat: /proc/1/environ: Permission denied

(Process 11882 in the example above is my current shell. Process 1 is init, of course.)

As /proc is a virtual filesystem, these file permissions are automatically generated whenever someone tries to read the files/directories under /proc. So the permissions can't really be changed to cause security breaches.

So now we know that the original perl script on Linux was either run as the same user than the interesting process, or run as root.

MK
MK
Honored Contributor Honored Contributor

Re: how do i get the environment variables of a proces?

Hi,

Please take a moment to assign points to those who have taken the time to assist you. Here's how:

http://forums1.itrc.hp.com/service/forums/helptips.do?#33

Thanks,

Gary
Occasional Visitor

Re: how do i get the environment variables of a proces?

done.