Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- int main(int argc, char* argv[])
- {
- int fd;
- struct flock lck;
- fd = open("file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600);
- lck.l_type = F_WRLCK;
- lck.l_whence = SEEK_SET;
- lck.l_start = 10;
- lck.l_len = 5;
- if ( -1 == (fcntl(fd, F_SETLKW, &lck) ) ) {
- exit(3);
- }
- write(fd, argv[1], 1);
- sleep(5);
- close(fd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement