title: How to kill multiple PIDs with one script and make it return to prompt
body: <p>I have two PID that are running in my linux server.</p>
  
  <p>When I do followin command they give me back the PID:</p>
  
  <pre><code>pgrep -f -d ' ' /'main.py'
  </code></pre>
  
  <p><code>4752 4768</code></p>
  
  <p>And here they are with command: <strong>ps -ef | grep main.py</strong></p>
  
  <pre><code>ubuntu    4752  4749  3 08:07 pts/1    00:00:04 python /home/ubuntu/deploy/main.py 
  ubuntu    4768  4752  5 08:07 pts/1    00:00:05 /home/ubuntu/venvs/myvirtual/bin/python /home/ubuntu/deploy/main.py
  </code></pre>
  
  <p>Now, I wanted to write a small shell script that when I run it, It will kill both PIDs. My script looks like this:</p>
  
  <pre><code>#!/bin/sh
  
  PID=`pgrep -f -d ' ' /'main.py'`
  
  if [ -z "$PID" ]; then
      echo "no pid found for main.py"
  else
      echo -ne '\n' | nohup kill -KILL $PID 1&gt;&amp;2 &amp;
  fi
  </code></pre>
  
  <p><strong>The problem is, when I run this script (./shutdown.sh) .. it first prints this:</strong></p>
  
  <pre><code>-bash: line 56:  4727 Killed   nohup python ~/deploy/main.py &gt; /home/ubuntu/main.log 2&gt;&amp;1
  </code></pre>
  
  <p><strong>... then I have to press [ENTER] to get back to prompt and it then prints:</strong></p>
  
  <pre><code>[1]+  Exit 137  . ~/venvs/myvirtual/bin/activate &amp;&amp; nohup python ~/deploy/main.py &gt; /home/ubuntu/main.log 2&gt;&amp;1  (wd: ~/deploy)
  (wd now: ~)
  </code></pre>
  
  <p>1) How do I make it kill the PIDs and just return to prompt cleanly without me hitting a RETURN button after script is run? </p>
  
  <p>2) Is there also a way to make the script fail if PID killing does not happen?</p>