I've got a problem with the following code:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc, char*argv[]){
FILE * tube;
char chaine[10];
mkfifo("glue", 0666);
tube = fopen("glue", "r");
while(1){
fgets(chaine, 10, tube);
printf("%s\n", chaine);
}
}
It's a program that mimics a server behavior, however when I run it on my Ubuntu Machine, either Windows 10 Ubuntu subsystem or the normal OS, the mkfifo line returns this error:
Segmentation Fault(core dumped)
Pls Help!
EDIT:
Forgot to send the version with the mkfifo test:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
int main(int argc, char*argv[]){
FILE * tube;
char chaine[10];
int errValue = mkfifo("glue", 0666);
perror("mkfifo");
if( errValue < 0){
printf("Error: %d\n", errValue);
exit(EXIT_FAILURE);
}
tube = fopen("glue", "r");
while(1){
fgets(chaine, 10, tube);
printf("%s\n", chaine);
}
}
The output of the program is:
mkfifo: Operation not permitted
Error: -1
And the one of umask is:
0000
And thank you immensely everyone for participating in this post!!:)
EDIT, PROBLEM SOLVED THANKS TO achal and everyone, thank you sooo much:
-One problem, the core one, was in using a 0022 umask instead of an 0002, thanks achal for this solution.
-The second problem was me using the Ubuntu subsystem for windows and try to run the program from CLI while it was located on the Windows desktop, windows doesn't give pipe permissions for the desktop apparently.
-The solution was to switch to my Ubuntu boot and change the umask and then it worked perfectly:)
Thanks to achal and everyone who participated in this post.
PROBLEM SOLVED.