Prevent duplicate shell script executions

Method #1, pidof

I have a /var/backup/systemBackup.sh for system backup.

edit /var/backup/runsystemBackup.sh

#!/bin/bash

if pidof -x "systemBackup.sh" >/dev/null; then
        echo "Process already running"
        exit 0
fi
/var/backup/systemBackup.sh  > /dev/null &

try run /var/backup/runsystemBackup.sh

Method #2, lock file

I have a /var/backup/systemBackup.sh for system backup.

edit /var/backup/runsystemBackup.sh

#!/bin/sh

lockdir=/tmp
BACKUP=/var/backup/systemBackup.sh
LOGGER=/usr/bin/logger

if [ ! -f /$lockdir/systemBackup.sh ]; then
        touch $lockdir/systemBackup.sh

        $BACKUP
        rm $lockdir/systemBackup.sh

else
        echo "systemBackup.sh already running"
        $LOGGER -d -t SYSTEM_Backup "systemBackup.sh already running"
fi

try run /var/backup/runsystemBackup.sh

Method #3, flock with cron job

# m h dom mon dow user  command
5 0  *  *  * flock -w 0 /tmp/sqlbackup.sh.lock /var/backup/systemBackup.sh