under Linux you can read the /proc/<pid>/environ file.Quote:> Is there a way for a program with superuser authority to read the current
> environment of any running process?
System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m
>>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 !?
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.
> You don't even need superuser privilege. On systems with /usr/ucb/ps, the
> -E option shows it.
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
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 */
(..): 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:
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
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