开发者

Waiting for named pipe to be opened in subscript in BASH?

I've got two scripts, one that takes a couple filenames as input and writes data to the pipes (really passes the pipes as arguments to program I wrote). And then the other one calls the first script with some named pipes as inputs and then calls so开发者_如何学编程me other programs to process the data from the pipes.

My problem is that my pipes are stalling and what I think is happening is the first bash script is called in the background from the second script, which then goes on to immediately start up the consumer processes, so I think the readers are being opened before the writers (in the subscript), which can cause a stall?

Is there a way to synchronize on a named pipe and wait for it to be opened in bash?


I don't think that's your problem.

If the producer starts later than the consumer, no big deal.

Example:

Window 1

$ mkfifo foo.pipe
$ cat foo.pipe
(hangs)

Window 2

$ echo 'something' > foo.pipe

Window 1

something
(exits)

Perhaps your problem is that one process is consuming the output of the fifo, then the producer quits, then you're trying to read from the fifo again.

In that case, it would hang indefinitely.

e.g. after the above sequence:

Window 1

$ cat foo.pipe

hangs until you run another echo something > foo.pipe.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜