setenv/clearenv + procfs environ
Asked Answered
N

1

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.

Nostradamus answered 3/4, 2013 at 6:0 Comment(4)
This author wrote a three (but not four) part explanation of why it doesn't already work. codywu2010.wordpress.com/2014/09/14/… codywu2010.wordpress.com/2014/09/14/… codywu2010.wordpress.com/2014/09/15/…Reliant
I also found some Perl folks trying to figure this out: perlmonks.org/?node_id=303181Reliant
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.Reliant
@Reliant 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.Nostradamus
B
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.

Boar answered 11/4, 2023 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.