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'm confused. Is my english so bad that no-one understands what I'm asking 
or is my understanding of SIGPIPE wrong?

> Can't you just close() the pipe?
Yes, of course. I wrote:

EF> Of course, when the tail exits, the head will get SIGPIPE as soon as it 
EF> tries to output something, but can the tail explicitly kill it earlier?
So yes, closing the tail of the pipe will deliver a SIGPIPE to the head,
but only as soon as it writes to the pipe, no? I was asking for a method 
to kill it even before it next tries to write something to the pipe.

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.

So the context is a collectd exec plugin translating envstat output to collectd 
PUTVALs. The structure is about

envstat -i 10 | while read ...
...
printf "PUTVAL ... || exit 1
...
done

Now the problem is that collectd sets a handler to ignore SIGPIPE, that's
inherited to the exec'd plugin (I could change that, after all, it's Open 
Source), so envstat continues to run.

After I realized what the problem was (SIGPIPE ignored), I thought what to do
and the obvious solution (apart from patching collectd) is to trap - PIPE 
before calling envstat. But since that would make envstat continue to run 
until it next tries to output something, I was asking myself whether there 
was a more elegant solution where I could explicitly kill envstat from within 
the while loop instead.
Of course, the question is not really relevant to envstat -i, but maybe 
I'll be facing a similar situation in the future where the head must be killed 
because no two incarnations may run at once or letting it continue is expensive 
or whatnot.


Home | Main Index | Thread Index | Old Index