If you want to lock "testfile", try and create a *new* "testfile.lock" in the same directory. Repeat (with ample sleep) until this succeeds. To unlock, simply remove the file. This method is supported by almost all configurations.
flock might be avail too
http://osr5doc.ca.caldera.com:457/cg.../man?flock+TCL