Check number of running scripts using ps

后端 未结 4 432
慢半拍i
慢半拍i 2021-01-15 06:09

I\'m writing a script (show_volume.sh) which may be called several times in short intervals. I need a way to determine whether there is more than just one running instance o

4条回答
  •  深忆病人
    2021-01-15 06:40

    At the moment ps runs a process grep show_volume.sh is also running, so you always count the grep!

    Simple solution, grep s[h]ow_volume.sh. The grep (not shell) will collapse the [h] to h and search for what you want, but your grep won't match itself because it will have [] in the parameter.

    pgrep is also useful for this task and is smart enough to always exclude itself.

提交回复
热议问题