Use flock to Ensure Only One Instance of a Shell Script Is Running 發表於 2017-02-16 | 12345678#!/usr/bin/env bashscript=$(realpath "$0")lock_file="${script%.*}.lock"( flock -n 9 || exit 1 sleep 10 && echo 'Done!') 9> "$lock_file" && rm "$lock_file" References: Unix manual flock(1)