title: Developing a correct understanding of waitpid() and getpid()
body: <p>I am learning about <code>forks</code>, <code>execl</code> and parent and child processes in my systems programming class. One thing that is confusing me is <code>waitpid()</code> and <code>getpid()</code>. Could someone confirm or correct my understanding of these two functions?</p>
  
  <p><strong>getpid()</strong> will return the process ID of whatever process calls it. If the parent calls it, it returns the pid of the parent. Likewise for the child.  (It actually returns a value of type <code>pid_t</code>, according to the manpages).</p>
  
  <p><strong>waitpid()</strong> seems more complex. I know that if I use it in the parent process, without any flags to prevent it from blocking (using <code>WNOHANG</code>), it will halt the parent process until the child process terminates. I'm a little unsure as to how <code>waitpid()</code> manages all this, however. <code>waitpid()</code> also returns <code>pid_t</code>. What is the value of the <code>pid_t</code> <code>waitpid()</code> returns? How does this change depending on whether or not a parent or child calls it, and whether or not a child process is still running, or has terminated?</p>