C: creating named pipe using mknod() not working -


language: c os: ubuntu

i'm trying create fifo named pipe using command:

state = mknod("pipe.txt", s_ififo | 0666, 0); 

the problem state's value -1 (meaning has failed) instead of 0.

perror returns 'pipe.txt: file exists'

i have no idea how should debug such issue or reason, hope code guide me what's wrong.

(note: file pipe.txt exist on same path source file.)

read: int mknod(const char *path, mode_t mode, rdev_t dev_identifier);
general description:
creates new character special file or fifo special file (named pipe), path name specified in path argument.

if file exists fails error: file exists

to avoid error, remove(unlink()) file, doing in below code(read comment):

int main() {   char* file="pipe.txt";   unlink(file);  // add before mknod()   int state = mknod(file, s_ififo | 0666, 0);   if(state < 0){     perror("mknod() error");   }   return 0; } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -