Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 8th, 2012  |  syntax: C  |  size: 0.39 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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