linux二重启动防止
生活随笔
收集整理的這篇文章主要介紹了
linux二重启动防止
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#!/bin/bash
# 2重起動チェック
function checkDuplicate()
{local RET=0local base=${0##*/}local pidfile="/tmp/${base}.pid"while true; doif ln -s $$ ${pidfile} 2> /dev/nullthen# 起動OKRET=0 && breakelsep=$(ls -l ${pidfile} | sed 's@.* @@g')if [ -z "${p//[0-9]/}" -a -d "/proc/$p" ]; thenlocal mypid=""for mypid in $(pgrep -f ${base})do[ ${p} -eq ${mypid} ] && RET=1 && breakdone;fi[ ${RET} -ne 0 ] && breakfirm -f ${pidfile}done# チェック結(jié)果を判定して、pidファイルを作成する。# 正常終了、シグナルを検知するとpidファイルを削除する。if [ ${RET} -eq 0 ]; thentrap "rm -f ${pidfile}; exit 0" EXITtrap "rm -f ${pidfile}; exit 1" 1 2 3 15fireturn ${RET}
}
用法
2重起動チェック checkDuplicate if [ 0 -ne $? ]; then# ここにエラー処理を書く fi--------------------------------------------------------------------------------
轉(zhuǎn)載自:http://qiita.com/KurokoSin/items/0eddf05818b89b627102
轉(zhuǎn)載于:https://www.cnblogs.com/ProBuster/p/3666091.html
總結(jié)
以上是生活随笔為你收集整理的linux二重启动防止的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python学习第八讲,python中的
- 下一篇: 窗口特效