3

I want to get the environment variables of process A from process B? There is no relationship with A and B. Not the System enviroment variables , but the enviroment variables that have been passed to the process!

In linux, or windows

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1337896
  • 1,081
  • 1
  • 10
  • 15
  • seems like its already answered http://stackoverflow.com/questions/2255968/view-environment-variable-of-process-on-windows – MitziMeow Jul 24 '12 at 09:17
  • Please make this question one environment or the other. As it stands, there are two valid answers, one of which [has already been given](http://stackoverflow.com/questions/2255968/view-environment-variable-of-process-on-windows). – Deanna Jul 24 '12 at 10:40
  • 1
    Please accept one of the answers if it answers your question. I see that you have asked 7 questions, including 6 upon which you received an answer for, but you never accepted even one as an answer to your question. It is the least you can do when someboy takes the trouble to give you an answer. – MarchingHome Oct 22 '12 at 07:55

2 Answers2

2

In Linux you can do this by reading (or mmaping) /proc/[pid]/environ. From proc(5):

/proc/[pid]/environ

This file contains the environment for the process. The entries are separated by null bytes ('\0'), and there may be a null byte at the end. Thus, to print out the environment of process 1, you would do:

      $ (cat /proc/1/environ; echo) | tr '\000' '\n'
Flexo
  • 87,323
  • 22
  • 191
  • 272
2

The environment variables are shown in /proc/PID/environ:

$ cat /proc/19065/environ
DISPLAY=localhost:0.0SHELL=/bin/bashPWD=/home/phil...

check out this question.

Community
  • 1
  • 1
Jeeva
  • 4,585
  • 2
  • 32
  • 56