2014年12月30日 星期二

[FW] Linux - shell script - detect multiple running instances of it self


Reference: http://giantdorks.org/alain/make-a-bash-script-quit-if-it-detects-multiple-running-instances-of-itself/

#!/bin/bash
if [ "$(pgrep -x $(basename $0))" != "$$" ]; then
 echo "Error: another instance of $(basename $0) is already running"
 exit 1
fi

沒有留言:

張貼留言