#include #include #include #include // lockf int main (int argc, char **argv) { int fd; if ( (fd = open(argv[1], O_RDWR)) <0) { printf("opening file %s failed\n",argv[1]); exit(1); } //if printf("locking file %s\n",argv[1]); lseek(fd, 0L, 0); // rewined to start of file if (lockf(fd, F_LOCK, 0L)) { printf("locking of file %s failed\n",argv[1]); exit(1); } else printf("file locked successfully\n"); getchar(); if (lockf(fd, F_ULOCK, 0L) == -1 ) { printf("cannot unlock file %s\n",argv[1]); exit(1); } else printf("file %s successfully unlocked\n",argv[1]); return (0); } // main()