6

Is it possible to get relevant information from /proc/pid/environ file if process modified its environment? My tests show that setenv/putenv/clearenv don't update environ file. However, in bash its possible to call unset ENV and see changes in procfs.

nmikhailov
  • 1,413
  • 14
  • 24
  • 3
    This author wrote a three (but not four) part explanation of why it doesn't already work. https://codywu2010.wordpress.com/2014/09/14/procfs-environ-explained-in-depth-1/ https://codywu2010.wordpress.com/2014/09/14/procfs-environ-explained-in-depth-2/ https://codywu2010.wordpress.com/2014/09/15/procfs-environ-explained-in-depth-3/ – jtolds Aug 23 '16 at 20:11
  • 1
    I also found some Perl folks trying to figure this out: http://www.perlmonks.org/?node_id=303181 – jtolds Aug 23 '16 at 20:11
  • 2
    Ultimately, I believe this is not possible (despite really hoping it is). My guess why you're seeing different behavior in bash is that however you're checking the environment is actually running in a subshell. – jtolds Aug 23 '16 at 20:12
  • @jtolds I tried my bash example and it didn't worked. So might be that I was indeed mistaken in the first place. Seems like its indeed impossible. You can add this as an answer if you want. – nmikhailov Aug 25 '16 at 14:59

1 Answers1

1

According to man proc, under /proc/[pid]/environ,

If, after an execve(2), the process modifies its environment (e.g., by calling functions such as putenv(3) or modifying the environ(7) variable directly), this file will not reflect those changes.

So, it doesn't appear to be possible.

Daniel Walker
  • 6,380
  • 5
  • 22
  • 45