1. file descriptors are unique per process ID – they can be found in /proc/your_process_id/fd folder
  2. small numbers from 0 – 9 are mostly used by system – 0, 1, 2 are stdin, stdout, stderr
  3. if you need to lock file in script and you are afraid of unused file descriptor number – look at point 1 – your script runs as new process with its own PID so using some reasonably high number like 200 should be OK. You can always check in fd folder for your PID. But do not use numbers from 0 to 9.
  4. acquire lock on file:
    fd = 200
    exec {fd} > $filename.lock
    flock -n $fd
  5. to remove lock delete $filename.lock file