title: Detecting death of spawned process using Window CRT
body: <p>Executive summary: I need a way to determine whether a Windows process I've spawned via _spawnl and am communicating with using FDs from _pipe has died.</p>
  
  <p>Details:</p>
  
  <p>I'm using the low-level CRT function in Windows (_eof, _read) to communicate with a process that was spawned via a call to _spawnl (with the P_NOWAIT) flag.  I'm using _pipe to create file descriptors to communicate with this spawned process and passing those descriptors (the FD #) to it on the command line.</p>
  
  <p>It is worth mentioning that I don't control the spawned process.  It's a black box to me.</p>
  
  <p>It turns out that the process we are spawning occasionally crashes.  I'm trying to make my code robust to this by detecting the crash.  Unfortunately, I can't see a way to do this.  It seems reasonable to me to expect that a call to _eof or _read on one of those descriptors would return an error status (-1) if the process had died.</p>
  
  <p>Unfortunately, that isn't the case.  It appears that the descriptors have a life of their own independent of the spawned process.  So even though the process on the other end is dead, I get no error status on the file descriptor I'm using to communicate with it.</p>
  
  <p>I've got the PID for the nested process (returned from the _spanwnl call) but I don't see anything I can do with that.  My code works really well except for one thing.  I can't detect whether the spawned process is simply busy computing me an answer or has died.</p>
  
  <p>If I can use the information from _pipe and _spawnl to determine if the spawned process is dead, I'll be golden.</p>
  
  <p>Suggestions very welcome.</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>UPDATE</strong>: I found a fairly simple solution and added it as the selected answer.</p>