title: fork(): way for a child process to check if parent is dead?
body: <p><strong>Background</strong></p>
  
  <p>I am writing a shared library in C, dynamically linked with <code>LD_PRELOAD</code>, that is meant to intercept and override network calls from the application preloading it, such as <code>socket()</code>, <code>connect()</code>, <code>recv()</code>, <code>send()</code>, etc.</p>
  
  <p>In the init of the library I launch a thread with <code>pthread_create()</code>. This thread polls some kernel memory, which is mapped to user space.</p>
  
  <p>The library is meant to be generic enough to deal with - but not limited to - networking benchmark applications such as <em>netperf</em>, <em>iperf</em>, <em>sockperf</em>.</p>
  
  <p><strong>My issue</strong></p>
  
  <p>Everything works fine, life is sweet in most of the cases except one. Deamonized applications. For instance, if I launch <em>netserver</em> (the server side of the <em>netperf</em> benchmarking application) as a deamon, i.e. without the <code>-D</code> parameter, one of the first things the application does is call <code>fork()</code>. On fork, the parent is closed using <code>exit(EXIT_SUCCESS)</code> and the child listens for connections. The fact that the parent exits kills my polling thread. </p>
  
  <p>So what I'd like to achieve is have the child spawn a new polling thread if the parent has gone. I can intercept and override the <code>fork()</code> call but fundamentally, how can I have the child know whether the parent has gone or not? I can't take any assumption because the library has to be generic.</p>
  
  <p>Thanks.</p>