kill-process.sh

来自「Shall高级编程」· Shell 代码 · 共 36 行

SH
36
字号
#!/bin/bash# kill-process.shNOPROCESS=2process=xxxyyyzzz  # Use nonexistent process.# For demo purposes only...# ... don't want to actually kill any actual process with this script.## If, for example, you wanted to use this script to logoff the Internet,#     process=pppdt=`pidof $process`       # Find pid (process id) of $process.# The pid is needed by 'kill' (can't 'kill' by program name).if [ -z "$t" ]           # If process not present, 'pidof' returns null.then  echo "Process $process was not running."  echo "Nothing killed."  exit $NOPROCESSfi  kill $t                  # May need 'kill -9' for stubborn process.# Need a check here to see if process allowed itself to be killed.# Perhaps another " t=`pidof $process` " or ...# This entire script could be replaced by#        kill $(pidof -x process_name)# or#        killall process_name# but it would not be as instructive.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?