fifo

Why does a read-only open of a named pipe block?

蹲街弑〆低调 提交于 2019-11-27 17:35:06
I've noticed a couple of oddities when dealing with named pipes (FIFOs) under various flavors of UNIX (Linux, FreeBSD and MacOS X) using Python. The first, and perhaps most annoying is that attempts to open an empty/idle FIFO read-only will block (unless I use os.O_NONBLOCK with the lower level os.open() call). However, if I open it for read/write then I get no blocking. Examples: f = open('./myfifo', 'r') # Blocks unless data is already in the pipe f = os.open('./myfifo', os.O_RDONLY) # ditto # Contrast to: f = open('./myfifo', 'w+') # does NOT block f = os.open('./myfifo', os.O_RDWR) # ditto

How do I properly write to FIFOs in Python?

末鹿安然 提交于 2019-11-27 17:30:10
问题 Something very strange is happening when I open FIFOs (named pipes) in Python for writing. Consider what happens when I try to open a FIFO for writing in a interactive interpreter: >>> fifo_write = open('fifo', 'w') The above line blocks until I open another interpreter and type the following: >>> fifo_read = open('fifo', 'r') >>> fifo.read() I don't understand why I had to wait for the pipe to be opened for reading, but lets skip that. The above code will block until there's data available

What conditions result in an opened, nonblocking named pipe (fifo) being “unavailable” for reads?

白昼怎懂夜的黑 提交于 2019-11-27 14:48:10
问题 Situation: new_pipe = os.open(pipe_path, os.O_RDONLY | os.O_NONBLOCK) # pipe_path points to a FIFO data = os.read(new_pipe, 1024) The read occasionally raises errno -11: Resource temporarily unavailable. When is this error raised? It seems very rare, as the common cases return data: If no writer has the pipe opened, empty str ('') is returned. If the writer has the pipe opened, but no data is in the fifo, empty str ('') is also returned And of course if the writer puts data in the fifo, that

NSOperationQueue serial FIFO queue

你说的曾经没有我的故事 提交于 2019-11-27 13:39:45
Is it possible to use an NSoperationQueue object as a serial FIFO queue by setting its maxConcurrentOperationCount to 1? I note that the docs state... For a queue whose maximum number of concurrent operations is set to 1, this equates to a serial queue. However, you should never rely on the serial execution of operation objects. Does this mean that FIFO execution is not guaranteed? In most cases, it will be FIFO. However, you can set up dependencies between NSOperations such that an operation submitted early will let other operations pass it by in the queue until its dependencies are satisfied

Named Pipes (FIFOs) on Unix with multiple readers

空扰寡人 提交于 2019-11-27 12:38:16
I have two programs, Writer and Reader. I have a FIFO from Writer to Reader so when I write something to stdin in Writer, it gets printed out to stdout from Reader. I tried doing this with TWO Readers open, and I got output to stdout from only one of the two Reader programs. Which Reader program Unix chooses to print stdout from seemed to be arbitrary each time I run this, but once it chooses one of the programs, each output to stdout gets printed from the same Reader program. Does anyone know why this happens? If I have two WRITER programs, they both write to the same pipe okay. The O in FIF

Create Named Pipe C++ Windows

心不动则不痛 提交于 2019-11-27 10:58:08
I am trying to create a simple comunication between 2 processes in C++ ( Windows ) like FIFO in linux. This is my server: int main() { HANDLE pipe = CreateFile(TEXT("\\\\.\\pipe\\Pipe"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); ConnectNamedPipe(pipe, NULL); while(TRUE){ string data; DWORD numRead =1 ; ReadFile(pipe, &data, 1024, &numRead, NULL); cout << data << endl; } CloseHandle(pipe); return 0; } And this is my client: int main() { HANDLE pipe = CreateFile(TEXT("\\\\.\\pipe\\Pipe"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); ConnectNamedPipe

How do I perform a non-blocking fopen on a named pipe (mkfifo)?

蹲街弑〆低调 提交于 2019-11-27 09:13:24
If I have a program which creates and attempts to open a named pipe using mkfifo, how can I open a pipe for reading or writing without blocking? Specifically, I'm writing a C program which can be run with or without a gui (written in Java). In the C program, I successfully create the named pipes using mkfifo, however when I do FILE* in = fopen(PIPE_IN, "r"); /* Where PIPE_IN is the filename*/ fopen doesn't return until the GUI opens that pipe for writing. What I wish to do is have that pipe ready to be read once (if) the GUI decides to write to it - I'll be putting the file descriptor in a

forcing a program to flush its standard output when redirected

廉价感情. 提交于 2019-11-27 08:29:00
i have a closed source program that prints output to standard output. i need to parse the output. so i redirect the output to a fifo (from which i can read in the parent process that forks and execs the binary) using dup2 and then exec the program. the problem is that the fprintf calls in the file become buffered because it is now writing to a file. i tried calling setvbuf with _IONBF on stdout before calling exec. but the problem still exists. why does setvbuf not help in my case? how can i force the output to get flushed? j_random_hacker setvbuf() makes no difference because it changes the

进程、线程以及IPC---linux

牧云@^-^@ 提交于 2019-11-27 07:08:05
进程(标识pid) <unistd.h> <sys/types.h> 资源集合:内存 文件 时间片 协处理器 完全复制:复制前执行什么,复制后执行什么 fork() 系统调用函数fork()是创建一个新进程的唯一方式 一次复制一个进程 返回值-1,创建失败; 返回值 0,进入子进程; 一般来说,fork()成功之后,父进程与子进程的执行顺序是不确定的。这取决于内核所使用的调度算法,如果要求父子进程相互同步,则要求某种形式的进程间通信。 vfork() 执行次序: fork():对父子进程的调度室由调度器决定的; vfork():是先调用子进程,等子进程的exit(1)被调用后,再调用父进程; 对数据段的影响: fork():父子进程不共享一段地址空间,修改子进程,父进程的内容并不会受影响。 vfork():在子进程调用exit之前,它在父进程的空间中运行,也就是说会更改父进程的数据段、栈和堆。即共享代码区和数据区,且地址和内容都是一样的。 IPC机制(6种) 管道(Pipe)及有名管道(named pipe): 管道可用于具有亲缘关系进程间的通信,有名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允许无亲缘关系进程间的通信; 信号(Signal): 信号是比较复杂的通信方式,用于通知接受进程有某种事件发生,除了用于进程间通信外,进程还可以发送信号给进程本身

How to work with “FIFO” in C# .NET?

♀尐吖头ヾ 提交于 2019-11-27 06:33:46
问题 Is there a standard collection in .NET that implements a FIFO stack? 回答1: FIFO means first-in-first-out. The data structure you're looking for is called a Queue. 回答2: FIFO means first in first out. This is as opposed to LIFO (or FILO as lucero pointed out). which is last in first out. A link comparing queues, stacks, and hashtables. You want to use a queue object for FIFO operations: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=66 MSDN link on queues And a stack is used for