title: How to kill a program by the hard way, only if it refuses to terminate the soft way?
body: <p><strong>How to exit a program by bash on a soft way and if this was not successful do it on a hard way.</strong></p>
  <ul>
  <li><p>Its known how to open a programm by bash and how to get the PID of the programm. The follow sample open the editor XED:</p>
  <p>xed &amp; PID=$!</p>
  </li>
  <li><p>Its known how to echo the PID of the program what was opened:</p>
  <p>echo $PID</p>
  <p>12345 # sample output of a PID</p>
  </li>
  <li><p>Its known how to try to close a program on a soft way and how to select the program by PID for this:</p>
  <p>kill -15 $PID # select a program by PID and tray to kill it on a soft way</p>
  </li>
  <li><p>Its known how to close a program on a hard way and how to select the program by PID for this:</p>
  <p>kill -9 $PID # select a program by PID and kill it on a hard way</p>
  </li>
  </ul>
  <p>Put all together what I have, a still missing something:</p>
  <pre><code>xed &amp; PID=$! # open the program xed and get the pid
  echo PID of programm: $PID
  
  sleep 5 # lets run the xed 5 seconds
  
  kill -15 $PID # select the xed by PID and try to kill it on soft way
  
  # check based on variant 1, 2, 3 or other, the xed was sucessfull killed on soft way or not
  # if the xed still running, kill it on follow way
  
  kill -9 $PID # select the xed by PID and kill it on hard way
  </code></pre>