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

前端 未结 30 2409
忘掉有多难
忘掉有多难 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条回答
  •  -上瘾入骨i
    2020-11-22 03:08

    There's a wrapper around the flock(2) system call called, unimaginatively, flock(1). This makes it relatively easy to reliably obtain exclusive locks without worrying about cleanup etc. There are examples on the man page as to how to use it in a shell script.

提交回复
热议问题