title: Bash function to kill process
body: <p>I made an alias for this function in order to kill processes in bash:</p>
  
  <p>On my <strong>.bashrc</strong> file</p>
  
  <pre><code>  kill_process(){
      # $1 being a parameter for the process name
      kill $(ps ax | grep "$1" | awk '{print $1}')
  }
  
  alias kill_process=kill_process
  </code></pre>
  
  <p>So, suppose I want to kill the <code>meteor</code> process:</p>
  
  <p><em>Let's see all meteor processes:</em></p>
  
  <pre><code>ps aux | grep 'meteor' | awk '{print $2}' 
  
  21565
  21602
  21575
  21546
  </code></pre>
  
  <p><em>Calling the <code>kill_process</code> function with the alias</em> </p>
  
  <pre><code>kill_process meteor
  
  bash: kill: (21612) - No such process
  </code></pre>
  
  <p>So, the <code>kill_process</code> function effectively terminates the <code>meteor</code> processes, but it's <code>kill</code> command looks for an inexistent pid. Notice the pid <code>21612</code> wasn't listed by <code>ps aux | grep</code>.  <strong>Any ideas to improve the <code>kill_process</code> function to avoid this?</strong></p>