Check number of running scripts using ps
问题 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 of this script. I figured I could use ps , so I wrote this function in Bash: is_only_process(){ PCOUNT=`ps -a | grep show_volume.sh | wc -l` echo $PCOUNT if (( PCOUNT==1 )); then return 1 fi return 0 } So I added these 2 lines is_only_process sleep 4 and started this script once, but the output of echo $PCOUNT does not make