tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: sh: killing a pipe head from the tail



> Is there a sane way to kill a pipe's head from within the pipe's
> tail, at least on tail exit?

In general, no, I think there is not.  If the pipeline was generated by
a shell, and the shell wants to do that, it certainly can arrange to,
but that's not quite what you asked.  (I don't know of any shells that
do, possibly because it's rarely wanted; there's often no reason the
write end shouldn't be allowed to finish normally provided it doesn't
try to write to a dead reader.)

If you're willing to go sufficiently OS-dependent, you can do it with
fstat(1) (or local equivalent if on an OS that doesn't have fstat(1),
though this _is_ a NetBSD list) and some filtering - or, if you want
something C-level instead of sh-level, the APIs underlying that.  But,
in any case, you'll need to figure out what you want to do if there are
multiple processes with fds open on the write end of the pipe.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse%rodents-montreal.org@localhost
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Home | Main Index | Thread Index | Old Index