I have a process which is created by execve() from another program and a specific set of environment is passed to it. However, I would need to read a global environment variable that may or may not be set by the user based on certain aspects. For example, $PATH is set when the execve() is called, but if the user stes $LOWMEM=1
( export LOWMEM=1
) before the program is exec'ed, then the program will not make malloc()
calls larger than 1KB
.
when I do a getenv("LOWMEM")
call from the program it returns NULL
where as I have added LOWMEM=1
in /etc/enviroment
and echo $LOWMWM
shows the value as 1. But I don't see LOWMEM entry in /proc/<PID>/environ
. Whereas I had rebooted the system after adding the entry to the /etc/environment
.
Is it not possible to read global environment from a process running under specific environment without explicitly passing it from the parent process?
It seems most likely that you're clearing out the entry for LOWMEM while using execve
. Instead, it might be better to call setenv
for the new variables you want, either in the parent or in the child and then call execv
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.