title: when will /proc/<pid> be removed?
body: <p>Process A opened &amp;&amp; mmaped thousand of files when running. Then <code>killl -9 &lt;pid of process A&gt;</code> is issued. Then I have a question about the sequence of below two events.<br>
  a) <code>/proc/&lt;pid of process A&gt;</code> cannot be accessed.<br>
  b)  all files opened by process A are closed.</p>
  
  <p>More background about the question:<br>
  Process A is a multi-thread background service. It is started by cmd <code>./process_A  args1 arg2 arg3</code>.<br>
  There is also a watchdog process which checked whether process A is still alive periodically(every 1 second). If process A is dead, then restart it. The way watchdog checks process A is as below.<br>
  1) collect all numerical subdir under <code>/proc/</code><br>
  2) compares <code>/proc/&lt;all-pids&gt;/cmdline</code> with cmdline of process A. If these is a <code>/proc/&lt;some-pid&gt;/cmdline</code> matches, then process A is alive and do nothing, otherwise restart process A.</p>
  
  <p>process A will do below stuff when doing initialization.<br>
  1) open fileA<br>
  2) flock fileA<br>
  3) mmap fileA into memory<br>
  4) close fileA<br>
  process A will mmap thousand of files after initialization.
  after several minutes, <code>kill -9 &lt;pid of process A&gt;</code> is issued. 
  watchdog detect the death of process A, restart it. But sometimes process A stuck at <code>step 2 flock fileA</code>. After some debugging, we found that unlock of fileA is executed when process A is killed. But sometimes this event will happen after <code>step 2 flock fileA</code> of new process.<br>
  So we guess the way to check process alive by monitor <code>/proc/&lt;pid of process A&gt;</code>
  is not correct.</p>