Operating System - Linux
1752754 Members
5083 Online
108789 Solutions
New Discussion юеВ

how do i get the environment variables of a proces?

 
Naoum
New Member

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 14
James R. Ferguson
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...
Naoum
New Member

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.
A. Clay Stephenson
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.
Court Campbell
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???"
Hein van den Heuvel
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.


Court Campbell
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???"
Hein van den Heuvel
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

Dennis Handly
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
Naoum
New Member

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.