I'm trying to check what happens if a process has an exclusive lock on a file and another process try to write on this file.
Will it fail or just block until the lock is lifted ?
To get an answer, I tried write something but it doesn't seem to be working I also tried to lock the same file from another program but it worked ?? I don't get any error when it should be impossible.
Am I doing something wrong ?
lock.c
int main()
{
int fd = open("okas", O_RDWR);
int n = flock(fd, LOCK_EX);
if (n == -1 )
{
perror("ok");
}
while (1)
{
}
}
write.c
int main()
{
int fd = open("okas", O_RDWR);
int n = write(fd, "1", 1);
printf("%d", n);
}