Based on my understanding 000 permission means no one is able to read or write to the file except the root user. Why does the following piece of code work?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(void)
{
char *message = "Hello world\n";
int fd = open("greeting.txt", O_CREAT | O_WRONLY, 0000);
write(fd, message, strlen(message));
close(fd);
}
Also when I make a named semaphore using sem_open(sem_name, O_CREAT, 0000, 1);
the parent and all of the child processes are able to modify it even though the file permission is set to 000.
My understanding of low-level C system calls and semaphores is limited so a thorough explanation would be appriciated.