开发者

Named pipes in c

I am trying to use named pipes in C and am running into some difficulty. In terms of anonymous pipes, I just create the pipe with the r/w descriptors and then close the opposite end every time I want to do a read or write. This is easy to do since I can just open() and close() the other end开发者_开发知识库 every time.

With named pipes, I am a bit confused, I found the instruction mkfifo() which creates the named pipe but don't understand how to read and write to it properly.

Thanks


After the pipe has been created with mkfifo() (which could have been done at any point in the past - named pipes exist in the filesystem until they're unlinked), the reading side opens it using open("/path/to/pipe", O_RDONLY) and the writing side opens it with open("/path/to/pipe", O_WRONLY).

After that it can be used just like an anonymous pipe.


There's nothing much to it. Use mkfifo to make the pipe and then have your processes read and write to it like any file. It's not C specific either. You can do this:

mkfifo testfifo

cat testfifo

And then in another window

echo "hello, world" > testfifo


I think you should just use the pipes, cause they handle the data transmission among the different processes no matter the time each proccess takes

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜