I'm looking to call a subprocess with a file descriptor opened to a given pipe such that the open() call does not hang waiting for the other side of the pipe to receive a connection.
To demonstrate:
$ mkfifo /tmp/foobar.pipe
$ some_program --command-fd=5 5</tmp/foobar.pipe
In this case, some_program
is not run until some process has /tmp/foobar.pipe
open for write; however, some_program
has useful effects even when it isn't receiving commands, so desired behavior is for some_program
to be immediately executed.
Mechanisms to do this by exec'ing through an alternate scripting language (python, perl, etc) or a C wrapper which open /tmp/foobar.pipe
with the O_NONBLOCK
flag are obvious; I'm looking for a pure-bash solution, should one be possible.