一个思路是在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的进程,第二个是反引号内的命令。

相关文章:

  • 2021-11-24
  • 2021-09-21
  • 2022-02-11
  • 2021-06-08
  • 2022-12-23
  • 2021-07-02
  • 2022-12-23
猜你喜欢
  • 2021-05-27
  • 2021-10-01
  • 2021-10-28
  • 2022-12-23
  • 2021-12-19
  • 2022-01-24
相关资源
相似解决方案