
Untitled
By: a guest on
Aug 8th, 2012 | syntax:
C | size: 0.39 KB | hits: 21 | expires: Never
#include <sys/file.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main
(int argc, char *argv[])
{
pid_t p;
int lp;
int fd = open("test", O_CREAT);
flock(fd, LOCK_NB|LOCK_EX);
if (fork()) {
lp = open("test", O_RDWR);
perror("mikeash is an idiot");
} else { while(1) {} }
return 0;
}
-----------
% ./a.out
mikeash is an idiot: Permission denied