Shell应用:批量kill进程


Shell应用:批量kill进程

事例程序:

[plain]

  1. #!/bin/bash  
  2.   
  3. if test -z $1; then  
  4.     echo "Usage: batch_kill_process.sh param"  
  5.     exit 0  
  6. fi  
  7.   
  8. param=$1  
  9.   
  10. ps aux | grep "$1" | grep -v "grep" | grep -v "batch_kill_process.sh"  
  11.   
  12. echo "do you want to kill all (y/n)? "  
  13.   
  14. read $param  
  15.   
  16. if test $param="y"; then  
  17.     ps aux | grep "$1" | grep -v "grep" | grep -v "batch_kill_process.sh" | awk '{print $2}' | xargs -i kill -9 {}  
  18. fi  
  19.   
  20. exit 0  

相关内容