简体   繁体   中英

Can we read environment variables of child from parent process

I know that fork will create a child process and then execve in the child process will execute the program setting some environment variables.

My task here is, My parent process parent1 has initially created a child process Child1 following the fork/exec procedure and set an Environment variable "CHILD=first".

Later in the execution of parent process, I have created another child process Child2 following the same fork/exec procedure. This child2 has an environment variable set as "CHILD=second".

Now, later in the execution of parent process, I have to read all the environment variables of child1 and child2 from Parent1 for some operations based on the env values. Is it possible to read these child environment variables from parent process? If so, how can I do it?

You can read the environment from /proc/<pid>/environ , on Linux. The variables are separated by nul-characters.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM