Here's how to lock them using flock in bash:
function delicate_process() { # the 'locked down' code return 0; } function main() { ( if ! flock -x --nonblock 200; then return 1; fi delicate_process; ) 200>/var/lock/.my.lock } main "${@}";This is essentially opening the file /var/lock/.my.lock and assigning it the FD 200, then inside flock attempts a non blocking exclusive lock on the FD 200, returning `1` on failure.