Guest User

Untitled

a guest
Aug 8th, 2012
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.39 KB | None | 0 0
  1. #include <sys/file.h>
  2.  
  3. #include <fcntl.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6.  
  7. int main
  8. (int argc, char *argv[])
  9. {
  10.     pid_t p;
  11.     int lp;
  12.     int fd = open("test", O_CREAT);
  13.     flock(fd, LOCK_NB|LOCK_EX);
  14.     if (fork()) {
  15.         lp = open("test", O_RDWR);
  16.         perror("mikeash is an idiot");
  17.     } else { while(1) {} }
  18.     return 0;
  19. }
  20.  
  21. -----------
  22.  
  23. % ./a.out
  24. mikeash is an idiot: Permission denied
Advertisement
Add Comment
Please, Sign In to add comment