You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
460B

  1. #!/bin/bash
  2. echo "Input process name first"
  3. port=8016
  4. #一、根据端口号查询对应的pid,两种都行
  5. pid=$(netstat -nlp | grep :$port | awk '{print $7}' | awk -F"/" '{ print $1 }');
  6. #pid=$(ps -ef | grep 你的进程或端口 | grep -v grep | awk '{print $2}')
  7. #二、杀掉对应的进程,如果pid不存在,则不执行
  8. if [ -n "$pid" ]; then
  9. kill -9 $pid;
  10. fi
  11. if [ $? -eq 0 ];then
  12. echo "kill $pid success"
  13. else
  14. echo "kill $pid fail"
  15. fi