title: Kill a process and wait for the process to exit
body: <p>When I start my tcp server from my bash script, I need to kill the previous instance (which may still be listening to the same port) right before the current instance starts listening. </p>
  
  <p>I could use something like <code>pkill &lt;previous_pid&gt;</code>. If I understand it correctly, this just sends <code>SIGTERM</code> to the target pid. When <code>pkill</code> returns, the target process may still be alive. Is there a way to let <code>pkill</code> wait until it exits?</p>