Sure, it's called open(). I was just commenting on what is actually happening. To a newbie you just cutting out some code, it's not essential to know that this is an atomic kernel call.
Uh, I see the testing step at the top of the program, then the create-a-lockfile later. Maybe you knew that this wasn't the real logic of the program, but you sure didn't communicate that in a way that wasn't going to bite the newbies.