How to get current ENV for a process

How to get current ENV for a process

Post by Jon Johnso » Sat, 06 Jul 2002 03:34:36



Is there a way for a program with superuser authority to read the current
environment of any running process?
 
 
 

How to get current ENV for a process

Post by Nils O. Sel?sda » Sat, 06 Jul 2002 04:14:01


In reply to Jon Johnson:

Quote:> Is there a way for a program with superuser authority to read the current
> environment of any running process?

under Linux you can read the /proc/<pid>/environ file.
Dont know if other OS's have, so someone else might answer for those.
- meaning there is probably no portable way of doing this !?

--

System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m

 
 
 

How to get current ENV for a process

Post by The Bea » Sat, 06 Jul 2002 04:36:21



> In reply to Jon Johnson:

>>Is there a way for a program with superuser authority to read the current
>>environment of any running process?

> under Linux you can read the /proc/<pid>/environ file.
> Dont know if other OS's have, so someone else might answer for those.
> - meaning there is probably no portable way of doing this !?

I did see this while trying to find answers to my problem, maybe it will help
There is also another section that follows this

http://www.geocities.com/capitalware/unix_faq_2.html#SEC7

The Bear

 
 
 

How to get current ENV for a process

Post by Barry Margoli » Sun, 07 Jul 2002 01:05:53




>Is there a way for a program with superuser authority to read the current
>environment of any running process?

You don't even need superuser privilege.  On systems with /usr/ucb/ps, the
-E option shows it.

--

Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How to get current ENV for a process

Post by Donald McLachl » Sun, 07 Jul 2002 02:11:23





> >Is there a way for a program with superuser authority to read the current
> >environment of any running process?

> You don't even need superuser privilege.  On systems with /usr/ucb/ps, the
> -E option shows it.

Maybe you meant "ps -e"?

janus don> uname -a
SunOS janus 5.8 Generic_108528-13 sun4u sparc SUNW,Sun-Blade-1000
janus don> /usr/ucb/ps -E
janus don> /usr/ucb/ps -e
   PID TT       S  TIME COMMAND
 26640 pts/3    S  0:00 [ sdt_shell ]
 26643 pts/3    S  0:00 [ csh ]
 26661 pts/3    S  0:00 /usr/dt/bin/dtsession MANPATH=/usr/dt/man:/usr/man:/usr
 26681 pts/4    S  0:00 -csh MANPATH=/usr/dt/man:/usr/man:/usr/openwin/share/ma
 26706 pts/5    S  0:00 /bin/csh MANPATH=/usr/dt/man:/usr/man:/usr/openwin/shar
 27942 pts/5    S  2:30 netscape MANPATH=/usr/man:/usr/local/man:/usr/local/lan
 27943 pts/5    S  0:00 (dns helper) MANPATH=/usr/man:/usr/local/man:/usr/local
 26705 pts/6    S  0:00 /bin/csh MANPATH=/usr/dt/man:/usr/man:/usr/openwin/shar

(use /usr/ucb/ps -eww to get "full" env)

--

Communications Research Centre / RNS    Tel     (613) 998-2845
3701 Carling Ave.,                      Fax     (613) 998-9648
Ottawa, Ontario
K2H 8S2
Canada

 
 
 

How to get current ENV for a process

Post by J.N.Subrahmanya » Thu, 11 Jul 2002 19:19:55


'ps' command on AIX, supports both X/open as well as Berkeley standards.
Under the Berkeley standards,  'ps   eww'  will show the entire list of
environment variables being used by a process.

Regards,
J.N.Subrahmanyam


> Is there a way for a program with superuser authority to read the current
> environment of any running process?

 
 
 

1. How /usr/ucb/ps -e gets env of process ?

Hi,

In Solaris 2.x, how does /usr/ucb/ps (BSD ps) with flag -e gets the
environment variables of a process ?

I tried ioctl call with POICPSINFO flag, which, according to
/usr/include/sys/procfs.h prpsinfo_t structure, contains the field:

       char    **pr_envp;      /* initial environment vector */

prpsinfo_t p;
(..): get fildes
ioctl (fildes, PIOCPSINFO, &p);

But I cannot follow the pointer because *pr_envp points to a bad address.

The proc man page says that:

  PIOCPSINFO
     This returns miscellaneous process information such as  that
     reported  by  ps(1).  p is a pointer to a prpsinfo structure
     containing at least the following fields:

(..) following is a list of field were pr_envp is not included.

If this field is defined in the struct but not filled by the ioctl call,
then how does the BSD ps program get the environment variable info ?

A truss on BSD ps -e shows that is does a ioctl PIOCPSINFO, then does a
pread on the /proc/xxx file descriptor with a misterious address twice.
The second pread gives back the environement string. how does it work ???

Thanks for help

Francois

--

Ecole d'Ingenieurs de Geneve                 tel:+41-(22)-344 77 50 ext:445
Rue de la Prairie 4                          fax:+41-(22)-344 92 88
CH-1202 Geneva SWITZERLAND

2. How to get Perl for Red Hat Linux 5.2?

3. getting owner(uid) of current process in Kernel extensions

4. Delayed sound with Via686a

5. process number of current process..BASH

6. i386 UNIX 'as' Assembler syntax

7. how to get kdelnk file to inherit current ENV?

8. error NETDEV WATCHDOG

9. Getting the process ID of a new process

10. Getting process information/Controlling process resource usage

11. Problem getting Env Vars with Mod_SSL

12. daemon gets passwds from ENV ?

13. Getting the value of env variables through read