#define _FILE_OFFSET_BITS 64 #include #include #include static struct flock lock = { F_WRLCK, SEEK_CUR, 0L, 0L }; int main () { static int fd; fd = open("dummy.lock", O_RDWR | O_CREAT, 0644); if (fd < 0) { perror("cannot open lockfile"); return 1; } if (fcntl(fd, F_SETLKW, &lock) == -1) { perror("cannot obtain exclusive lock"); return 2; } pause(); close(fd); return 0; }