i'm trying create fifo named pipe using mknod() command:
int main() { char* file="pipe.txt"; int state; state = mknod(file, s_ififo & 0777, 0); printf("%d",state); return 0; } but file not created in current directory. tried listing ls -l . state returns -1.
i found similar questions here , on other sites , i've tried solution suggested:
int main() { char* file="pipe.txt"; int state; unlink(file); state = mknod(file, s_ififo & 0777, 0); printf("%d",state); return 0; } this made no difference though , error remains. doing wrong here or there sort of system intervention causing problem?
help.. in advance
you using & set file type instead of |. docs:
the file type path or'ed mode argument, , application shall select 1 of following symbolic constants...
try this:
state = mknod(file, s_ififo | 0777, 0); because works:
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> int main() { char* file="pipe.txt"; int state; unlink(file); state = mknod(file, s_ififo | 0777, 0); printf("state %d\n", state); return 0; } compile it:
gcc -o fifo fifo.c run it:
$ strace -e trace=mknod ./fifo mknod("pipe.txt", s_ififo|0777) = 0 state 0 +++ exited 0 +++ see result:
$ ls -l pipe.txt prwxrwxr-x. 1 lars lars 0 jul 16 12:54 pipe.txt
Comments
Post a Comment