title: why did wait4() get replaced by waitpid()
body: <p>I was going through the documentation of the system call <a href="http://man7.org/linux/man-pages/man2/wait4.2.html" rel="noreferrer"><code>wait4()</code></a> and in its man page it is written</p>
  
  <blockquote>
    <p>These functions are obsolete; use <code>waitpid(2)</code> or <code>waitid(2)</code> in new programs.</p>
  </blockquote>
  
  <p>So, I went through the documentation of <a href="http://man7.org/linux/man-pages/man2/waitpid.2.html" rel="noreferrer"><code>waitpid()</code></a> and I saw that there is a difference between the two.</p>
  
  <p><a href="http://man7.org/linux/man-pages/man2/waitpid.2.html" rel="noreferrer"><code>waitpid()</code></a> does the same things as <a href="http://man7.org/linux/man-pages/man2/wait4.2.html" rel="noreferrer"><code>wait4()</code></a>, but <a href="http://man7.org/linux/man-pages/man2/wait4.2.html" rel="noreferrer"><code>wait4()</code></a>, according to the man page,</p>
  
  <blockquote>
    <p>additionally return resource usage information about the child in the structure pointed to by <code>rusage</code>.</p>
  </blockquote>
  
  <p>The two system calls are defined as follows</p>
  
  <pre><code>pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
  
  pid_t waitpid(pid_t pid, int *status, int options);
  </code></pre>
  
  <p>Now, I also read that there is a another system call that does that extra job of getting the <code>rusage</code> of the child and that is <a href="http://man7.org/linux/man-pages/man2/getrusage.2.html" rel="noreferrer"><code>getrusage()</code></a>.</p>
  
  <p>So, I can understand that what <code>wait4()</code> could do, one can do the same thing by using a combination of <code>waitpid()</code> and <code>getrusage()</code>.</p>
  
  <hr>
  
  <p>But, what I am not understanding is, there is always a strong reason for making a system call obsolete. But in this case it feels that the functionality has been split.</p>
  
  <ul>
  <li>If I want to use the combination of <code>waitpid()</code> and <code>getrusage()</code>, I
  have to check the return values twice, which was not the case for
  <code>wait4()</code>.</li>
  <li>Additionally one can use <code>wait4()</code> to get <code>rusage</code> of a specific
  child, but <code>waitpid()</code> would gives <code>rusage</code> of all its children
  together (if used with <code>RUSAGE_CHILDREN</code>). That sounds like extra overhead if there are more then few child processes.</li>
  </ul>
  
  <p>Why was <code>wait4()</code> made obsolete? It seems like it made things harder.</p>