BASH local and flock
问题 I try to use a flock like here https://stackoverflow.com/a/169969 but within a function ... and I try to update a local variable (locale to the function) from within the flock part, but it seems not update ... cat test.sh #!/bin/bash function _job_worker() { local z=1 local result= ( # Wait for lock on /var/lock/.manager.exclusivelock (fd 200) flock -x -w 10 200 || return z=2 echo "slot equal $z" ) 200>/var/lock/.manager.exclusivelock echo "slot equal $z" } _job_worker ./test.sh slot equal 2