Quick-and-dirty way to ensure only one instance of a shell script is running at a time

前端 未结 30 3019
忘掉有多难
忘掉有多难 2020-11-22 02:57

What\'s a quick-and-dirty way to make sure that only one instance of a shell script is running at a given time?

30条回答
  •  迷失自我
    2020-11-22 03:14

    PID and lockfiles are definitely the most reliable. When you attempt to run the program, it can check for the lockfile which and if it exists, it can use ps to see if the process is still running. If it's not, the script can start, updating the PID in the lockfile to its own.

提交回复
热议问题