DareDevil73

Linux Kill and Wait for process

Mar 23rd, 2016
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. DIR=<WORKING_DIRECTORY>
  2. PROCESS=<PROCESS_EXECUTABLE>
  3. FULL_PROCESS=$DIR/$PROCESS
  4.  
  5. GET_PID="pidof -s $FULL_PROCESS"
  6.  
  7. echo -n "Stopping \"$PROCESS\".."
  8.    
  9. PID="$($GET_PID)"
  10.  
  11. if [ $? -ne 0 ]; then
  12.   echo ". failed (not running)."
  13.   exit 1
  14. else
  15.   kill $PID > /dev/null
  16.   $GET_PID > /dev/null
  17.  
  18.   while [ $? -eq 0 ]
  19.   do
  20.     echo -n "."
  21.     sleep 1
  22.     $GET_PID > /dev/null
  23.   done
  24.  
  25.   echo ". done (PID = $PID)."
  26.   exit 0
  27. fi
Add Comment
Please, Sign In to add comment