本文介绍了我可以锁定和用C解锁FIFO(命名管道)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个进步, P1 P2 ,以及命名管道 VAR 2进步之间的IPC。结果
我想锁定的RW为 P2 P1 >写和解锁 VAR P1 完成写。结果

I have two progress, p1 and p2, and a named pipe var for ipc between 2 progress.
I want to lock var's rw for p2 when p1 writes, and unlock var when p1 finished write.

PS:

我使用select的非阻塞,因此 P2 将得到可读时 P1 把任何东西到 VAR 。可我让 VAR 成为可读时 P1 完成写?

I using select for nonblocking, so p2 will get readable when p1 put anything to var.Can I let var become readable when p1 finish write?

推荐答案

您可以使用信号(例如 SIGUSR1 )。笔者使它管非阻塞(所以当管道满也不会封锁),写入直到它再也不能写,然后将信号发送到另一个进程。读取处理中读取的所有(从其非阻塞管),然后发送一个信号给作家谁然后继续到写

You could use signals (e.g. SIGUSR1). The writer makes it pipe non-blocking (so it won't block when the pipe becomes full), writes until it can't write anymore, then send the signal to the other process. The reading process reads all (from its non-blocking pipe), then sends a signal to the writer who then continues to write.

不过,这实在是没有必要的。作家可以只写,读者刚刚读。如果管道已满笔者将阻塞,直到可以写更多。而对于读者一样时,如果没有什么读阻塞。然后,当作家写的所有数据,它会简单地关闭其管道,该读者将与返回读取的零字节通话检测结束。

However, this is really not needed. The writer can just write, and the reader just read. If the pipe becomes full the writer will block until it can write more. And the same for the reader, it will block if there's nothing to read. Then when the writer has written all data, it will simply close its end of the pipe, which the reader will detect with a read call that returns zero bytes read.

这篇关于我可以锁定和用C解锁FIFO(命名管道)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:46