Skip to content

Instantly share code, notes, and snippets.

@szastupov
Created December 23, 2011 00:43
Show Gist options
  • Save szastupov/1512518 to your computer and use it in GitHub Desktop.
Save szastupov/1512518 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
struct flock fl;
int fd;
fl.l_type = F_RDLCK; /* F_RDLCK, F_WRLCK, F_UNLCK */
fl.l_whence = SEEK_SET; /* SEEK_SET, SEEK_CUR, SEEK_END */
fl.l_start = 0; /* Offset from l_whence */
fl.l_len = 0; /* length, 0 = to EOF */
fl.l_pid = getpid(); /* our PID */
fd = open("/etc/dfs/sharetab", O_RDONLY);
fcntl(fd, F_SETLKW, &fl);
sleep(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment