title: Linux: Send mail after a process id finishes or is killed
body: <p>I want to be notified on my email after another user's process kills or finishes.  I can identify another user's process by its process id or the name of the process appearing in "top" command.</p>
  
  <p>In order to do the same I wrote the following script:</p>
  
  <pre><code>while true; do
    if ps -ef | grep -q 'process_name'; then
      sleep 1
    else
     echo "complete" | mail -s "process exiting" abc@gmail.com
    fi
  done
  </code></pre>
  
  <p>However, I find that even after another user's process finishes or the other user kills his or her process, still I am not getting any notification or email. Can someone please help me with this a bit.</p>