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

> I was asked about the context and what I was really trying to do.
> I didn't give the context because I thaught it was irrelevant.
> What I was really trying to do is partly trying to learn.

It is and it is is not (irrelevant, that is).

It is irrelevant to the questino you asked.  But people often ask "how
do I do XYZ?" when their problem is actually "how do I do ABC?" and
they believe XYZ is the only way (or sometimes, the correct way) to do
ABC.  Such people are often wrong; there are often other ways to do
ABC.  (If you want to sidestep such questions, a very brief sketch of
why you want to do XYZ can help.  In this case, saying something like
"I was looking at a problem which is irrelevant here, because it led me
to wonder if there's some way for the process on the read end of a pipe
to kill the process on the write end without depending on the writing
process getting SIGPIPE" might help make it clear that you're looking
for XYZ in its own right, independent of the ABC that motivated your
initial interest in it.

> So the context is [...]

Personally, I would call it a bug in collectd that it leaves SIGPIPE
ignored by plugin children it forks; that is not what least surprise
would lead me to expect.  I would say it'd be better for it to catch
SIGPIPE and have the catcher do nothing.  That way, it'd get reset for
free upon exec in the child.

It occurs to me that you might be able to do it by having the script
kill its entire process group.  This may or may not do what you want,
depending on what collectd and the shell in question do with process
groups.  It does seem to me like one of the cleaner possible solutions.

I'm not sure what I think of the idea that a pipe's reader can do
things to the pipe's writer without the writer's cooperation.  It
certainly is not traditional behaviour; if widely implemented I suspect
it would lead to scripts being written defensively with things like

	# cat process is so that b can't kill a prematurely
	... a | cat | b ...

which seems like...a step backwards, somehow, to me.

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Home | Main Index | Thread Index | Old Index