[TUHS] Excise process from a pipe

Christopher Vance cjsvance at gmail.com
Thu Jul 10 15:06:11 AEST 2014


On Thu, Jul 10, 2014 at 2:52 PM, Warren Toomey <wkt at tuhs.org> wrote:

> On Wed, Jul 09, 2014 at 10:49:22PM -0400, Doug McIlroy wrote:
> > It's easy for a process to insert a new process into a
> > pipeline either upstream or downstream. Was there ever a
> > flavor of Unix in which a process could excise itself
> > from a pipeline without breaking the pipeline?
>
> If in the middle of a pipeline, all I can think of is:
>
>         close fd 0 and fd 1
>         dup() read end of pipe 1 to be stdin (fd 0)
>         dup() write end of pipe 2 to be stdout (fd 1)
>         exec("/bin/cat")
>
> Cheers, Warren
> _______________________________________________
> TUHS mailing list
> TUHS at minnie.tuhs.org
> https://minnie.tuhs.org/mailman/listinfo/tuhs
>

Hi, Warren.

That still leaves a process, even if it is a relatively lean one. Besides
your fd 0 is presumably already the read end of the input pipe, and fd 1 is
already the write end of the output pipe. You could probably reduce the
whole thing to the last line.

I don't think Doug's request can be done without some new kernel call (or
other kernelly goodness) to munge file table entries (nomenclature?) for
the process on at least one side (or more likely both) of the self-excisor.
Someone may have done it, since I have heard rumours of some novel hacks,
but it presumably didn't get very far.

Assuming you have pipes on each side, consider what to do with any buffered
data.

-- 
Christopher Vance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20140710/e50cda86/attachment.html>


More information about the TUHS mailing list