zoukankan      html  css  js  c++  java
  • 防止shell script多次运行

    一个思路是在script初期检测系统中是否存在同名进程。

    if [ `ps -ef | grep "test.sh" | grep -v "grep" | wc -l` -gt 2 ]
    then
        echo "This script is already running. Exit."
    else
        while true
        do
            echo "I am running"
            sleep 5
        done
    fi

    如果是第一次运行,那么首行语句检测到的同名进程会有两个:第一个是启动这个script的进程,第二个是反引号内的命令。

  • 相关阅读:
    bzoj 4007
    bzoj 2190
    bzoj 2186
    bzoj 2005
    bzoj 2721
    bzoj 1951
    CF919F
    CF1005F
    CF1019C
    bitset用法详解
  • 原文地址:https://www.cnblogs.com/byeyear/p/10428020.html
Copyright © 2011-2022 走看看