Timeline for How to read environment variables of a process
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Mar 29, 2013 at 23:36 | history | edited | Stéphane Chazelas | CC BY-SA 3.0 | Gilles, that's what I guess you meant, please fix if not. |
| Mar 29, 2013 at 21:23 | comment | added | Gilles 'SO- stop being evil' | @JonathanBen-Avraham You're right that the initial environment isn't updated in any shell. However that area is not read only under Linux, I've encountered programs that use it to report their status (status reports through argv are more common but both exist). | |
| Mar 29, 2013 at 21:21 | history | edited | Gilles 'SO- stop being evil' | CC BY-SA 3.0 | no shell updates the static environment area, in fact (and for good reason: it's fixed-size) |
| Mar 29, 2013 at 13:24 | comment | added | Jonathan Ben-Avraham | @Gilles: This answer is at best misleading (-1). The environment in /proc/$$/environ is read from the process's stack. See fs/proc/base.c. This is the initial environment. It is never updated and in fact can't be. The environment that the libc setenv uses is allocated on the heap and initialized with the contents of the environment in the stack. If the process calls libc's fork then libc makes the sys_fork call using the heap allocated environment for the child process. | |
| Jan 15, 2012 at 17:00 | comment | added | Gilles 'SO- stop being evil' | @Nikhil Sure, it is. But just because you write PATH=foo in a shell doesn't mean the shell is going to modify *envp. In some shells, that only updated an internal data structure, and it's the external program execution code that updates *envp. Look at assign_in_env in variables.c in the bash source, for example. | |
| Jan 15, 2012 at 7:29 | comment | added | Nikhil Mulley | so, effectively there is no way to access the process' *envp (array of pointers to environment settings). @Gilles, can you please show if it is possible to attach the debugger and read the array of pointers to environment settings. | |
| Jan 15, 2012 at 6:06 | vote | accept | CommunityBot | ||
| Jan 15, 2012 at 2:49 | history | answered | Gilles 'SO- stop being evil' | CC BY-SA 3.0 |