The 200 in the shell script is a file descriptor — see the manual page for flock(1)
.
Your problem with the file permissions is that open(2)
takes 3 arguments when you include O_CREAT
; the third argument should be the permissions on the file. When you don't specify the third argument, you get some quasi-random value chosen for you. It takes a lot of analysis to help you detect that problem because open(2)
has the signature:
#include <fcntl.h>
int open(const char *path, int oflag, ...);
It is a variable-length argument list function, so using just two arguments is OK most of the time, except that when O_CREAT
is specified it needs the third argument.