Re: how do i get the environment variables of a proces? (216 Views)
Reply
Occasional Visitor
Naoum
Posts: 5
Registered: ‎04-10-2007
Message 1 of 15 (216 Views)

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?
Please use plain text.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 2 of 15 (216 Views)

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

Hi:

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

Regards!

...JRF...
Please use plain text.
Occasional Visitor
Naoum
Posts: 5
Registered: ‎04-10-2007
Message 3 of 15 (216 Views)

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.
Please use plain text.
Acclaimed Contributor
A. Clay Stephenson
Posts: 17,825
Registered: ‎07-16-1998
Message 4 of 15 (216 Views)

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.
Please use plain text.
Honored Contributor
Court Campbell
Posts: 1,605
Registered: ‎08-12-2004
Message 5 of 15 (216 Views)

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???"
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,579
Registered: ‎05-19-2003
Message 6 of 15 (216 Views)

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.


Please use plain text.
Honored Contributor
Court Campbell
Posts: 1,605
Registered: ‎08-12-2004
Message 7 of 15 (216 Views)

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???"
Please use plain text.
Honored Contributor
Hein van den Heuvel
Posts: 6,579
Registered: ‎05-19-2003
Message 8 of 15 (216 Views)

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

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,697
Registered: ‎03-06-2006
Message 9 of 15 (216 Views)

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
Please use plain text.
Occasional Visitor
Naoum
Posts: 5
Registered: ‎04-10-2007
Message 10 of 15 (216 Views)

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.
Please use plain text.
Honored Contributor
Ralph Grothe
Posts: 2,631
Registered: ‎04-09-2000
Message 11 of 15 (216 Views)

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
Please use plain text.
Occasional Visitor
Naoum
Posts: 5
Registered: ‎04-10-2007
Message 12 of 15 (216 Views)

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

Ralph, that's exactly what i meant. thanks.
Please use plain text.
Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 13 of 15 (216 Views)

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
Please use plain text.
Honored Contributor
Gary Cantwell
Posts: 2,725
Registered: ‎08-06-2002
Message 14 of 15 (216 Views)

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
Please use plain text.
Occasional Visitor
Naoum
Posts: 5
Registered: ‎04-10-2007
Message 15 of 15 (216 Views)

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

done.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation