Skip to content

Instantly share code, notes, and snippets.

@toya33
Last active October 6, 2015 15:01
Show Gist options
  • Save toya33/64687c810657cff31f46 to your computer and use it in GitHub Desktop.
Save toya33/64687c810657cff31f46 to your computer and use it in GitHub Desktop.
引数として渡されたプロセス名が起していれば
プロセスを強制終了する
process.sh
------------------------------
#!/bin/sh
#プロセス名を引数として受け取る
PROCESS_NAME=$0
#取得したプロセスを基にプロセスを検索
COMMAND_RESULT=`ps aux | grep $PROCESS_NAME | grep -v grep`
#プロセスlが起動していればプロセスを強制終了
echo "$COMMAND_RESULT" | grep "$PROCESS_NAME" >/dev/null 2>&1
if [ $? -eq 0 ]; then
killall -9 $PROCESS_NAME
fi
exit 0
------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment