title: Can the child process affect parent process' environment?
body: <p>What does "<em>the child inherits the parent's environment</em>" mean? Inherits by copying the whole environment, or inherits by receiving pointer to the same environment (somehow)?</p>
  
  <hr>
  
  <p>Here's my scenario:</p>
  
  <ol>
  <li>I have a running process <code>P</code> with its own environment (variables)</li>
  <li>At some point, <code>P</code> executes <code>fork</code></li>
  <li>In the <code>0</code>-clone of the <code>if-statement</code> (a.k.a. in the child process <code>C</code>), an <code>execv</code> is executed</li>
  <li>Both processes continue running independently.</li>
  </ol>
  
  <p>So, in some moment, the application stops working fine. And the reason is - "broken" environment. </p>
  
  <p>The interesting part is, that both environments are changed.. When I start the parent process and execute</p>
  
  <pre><code>$ cat /proc/PID/environ
  </code></pre>
  
  <p>for both - the parent and the process, everything is fine. Some hours later, the app stops working and when I execute the line above again (to check the environment), both are changed and a lot of environment variables are missing - only the standard ones are there (like <code>PWD</code>, <code>HOME</code>, <code>USER</code>, etc.).</p>
  
  <p>How is this possible? And where could the the problem - in the child or in the parent?</p>
  
  <hr>
  
  <p><em><strong>EDIT:</strong></em> Thanks all for the answers, +1 from me, as they were all correct ( @caf, @Saphrosit and @R..). The reason for this issue is really silly..</p>
  
  <p>All environment variables were placed in <code>/etc/profile</code> which is executed AFTER LOGIN (that.. I didn't know). </p>
  
  <p>Well, it appeared, that the issue have happened on restart of the machine. So, on start-up, the application is started again, but <code>/etc/profile/</code> is <strong>not</strong> executed/read. And this causes the bad behavior. And that's why the problem disappears on manual restart - once a <code>root</code> is logged in (through <code>ssh</code>), the environment variables from <code>/etc/profiles</code> are read, and when the parent process is restarted (by <code>root</code>), it's all fine - the environment variables are inherited. </p>
  
  <p>Stupid mistake.</p>