How to control a script is not already running?
问题 I have a shell script executed by cron and I want to control that it's not already running. This is my control test: set -A processes ps -elf | grep -v grep | grep -E "/bin/ksh.+scriptName" | while read line ;do processes[${#processes[@]}]="$line";done if [ ${#processes[@]} -gt 1 ]; then for i in {0..$((${#processes[@]}-1))}; do echo "${processes[$i]}"; done exit 1 fi The problem is that this control returns sometimes 2 processes (of itself): F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY