title: Why does vim crash when it becomes an orphan process?
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main()
  {
      int pid = fork();
      
      if (pid) {
          sleep(5);
          // wait(NULL); // works fine when waited for it.
      } else {
          execlp(&quot;vim&quot;, &quot;vim&quot;, (char *)NULL);
      }
  }
  </code></pre>
  <p>When I run this code, vim runs normally then crashes after the 5 seconds (i.e. when its parent exits). When I wait for it (i.e. not letting it become an orphan process), the code works totally fine.</p>
  <p>Why does becoming an orphan process become a problem here? Is it something specific to vim?</p>
  <p>Why is this even a thing that's visible to vim? I thought that only the parent knows when its children die. But here, I see that somehow, the child notices when it gets adopted, something happens and crashes somehow. Do the children processes get notified when their parent dies as well?</p>
  <p>When I run this code, I get this output after the crash:</p>
  <pre class="lang-none prettyprint-override"><code>Vim: Error reading input, exiting...
  Vim: preserving files...
  Vim: Finished.
  </code></pre>