FIFOs implementation

前端 未结 5 1163
悲哀的现实
悲哀的现实 2020-12-17 04:35

Consider the following code:

writer.c

mkfifo(\"/tmp/myfifo\", 0660);

int fd = open(\"/tmp/myfifo\", O_WRONLY);

char *foo, *bar;

...

write(fd, foo         


        
5条回答
  •  独厮守ぢ
    2020-12-17 04:55

    To generalize WhirlWind's answer slightly, you've got to establish a protocol of SOME variety. There has to be order to what you are sending or else you don't know top from bottom, as you point out.

    Both of WhirlWind's suggestions will work. You can also go so far as to implement a custom (or standard) protocol on top of a pipe or FIFO to make porting your code to a more distributed environment with disparate systems and easier task later. The crux of the issue, though, is that you've got to set RULES for communicating before you're able to actually communicate.

提交回复
热议问题