What's the best way to make sure only one instance of a Perl program is running?

后端 未结 3 1105
清歌不尽
清歌不尽 2020-12-13 19:50

There are several ways to do this, but I\'m not sure which one of them is the best.

Here\'s what I can think of:

  • Look for the process using pgrep.
3条回答
  •  伪装坚强ぢ
    2020-12-13 20:16

    All of the options that you list are fine. One thing with this though, is to be aware that in rare cases, you can end up with a process that runs for a very long time (i.e., stuck waiting on something). You might want to think about keeping an eye on how long the other running instance has been running and possibly send yourself an alert if it exceeds a certain amount of time (such as a day perhaps).

提交回复
热议问题