#define _GNU_SOURCE #include #include #include #include #include #include int main(void) { system("touch foo"); int fd = open("foo", O_RDWR); int ret = fcntl(fd, F_OFD_SETLK, &(struct flock){ .l_type = F_RDLCK }); printf("set rd lock: %i, %s\n", ret, strerror(errno)); system("./test2"); printf("===\n"); ret = fcntl(fd, F_OFD_SETLK, &(struct flock){ .l_type = F_UNLCK }); printf("unset lock: %i, %s\n", ret, strerror(errno)); system("./test2"); printf("===\n"); ret = fcntl(fd, F_OFD_SETLK, &(struct flock){ .l_type = F_WRLCK }); printf("set wr lock: %i, %s\n", ret, strerror(errno)); system("./test2"); close(fd); return 0; }