Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6.  
  7. int main(int argc, char* argv[])
  8. {
  9.     int fd;
  10.     struct flock lck;
  11.  
  12.     fd = open("file.txt", O_WRONLY | O_CREAT | O_TRUNC, 0600);
  13.  
  14.     lck.l_type      = F_WRLCK;
  15.     lck.l_whence    = SEEK_SET;
  16.     lck.l_start     = 10;
  17.     lck.l_len       = 5;
  18.  
  19.     if ( -1 == (fcntl(fd, F_SETLKW, &lck) ) ) {
  20.         exit(3);
  21.     }
  22.  
  23.     write(fd, argv[1], 1);
  24.  
  25.     sleep(5);
  26.     close(fd);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement