Store proper PID in locks database by forking before taking a lock

Please test extensively. Not even compile-tested (don't have an environment to compile it ATM).