|
Home > Archive > Unix Shell > December 2007 > Why does not tail exit here?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Why does not tail exit here?
|
|
| Mikhail Teterin 2007-12-19, 7:27 pm |
| Why does not the script below exit properly?
#!/bin/sh
if tail -f /var/log/messages | awk '{print "Exiting"; exit 0}'
then
echo Exited
else
echo Failed
fi
exit 0
Awk, actually, exits, but tail stays around. On BSD and Linux the entire
sh-script waits. On Solaris the sh-script completes, but the tail is left
hanging in the background -- forever.
Why does not tail exit automatically, when its stdout is closed? Thanks!
-mi
| |
| Barry Margolin 2007-12-19, 7:27 pm |
| In article <uvudnY-dLZ0KNfTanZ2dnUVZ_tmhnZ2d@speakeasy.net>,
Mikhail Teterin <usenet+mill@aldan.algebra.com> wrote:
> Why does not the script below exit properly?
>
> #!/bin/sh
>
> if tail -f /var/log/messages | awk '{print "Exiting"; exit 0}'
> then
> echo Exited
> else
> echo Failed
> fi
>
> exit 0
>
> Awk, actually, exits, but tail stays around. On BSD and Linux the entire
> sh-script waits. On Solaris the sh-script completes, but the tail is left
> hanging in the background -- forever.
>
> Why does not tail exit automatically, when its stdout is closed? Thanks!
It should exit the next time something is written to /var/log/messages.
At that time it will try to write it to the pipe, and get an error.
But it's not doing anything until then, so it doesn't notice that the
pipe has closed.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
| |
| Mikhail Teterin 2007-12-19, 7:27 pm |
| Barry Margolin wrote:
> It should exit the next time something is written to /var/log/messages.
> At that time it will try to write it to the pipe, and get an error.
>
> But it's not doing anything until then, so it doesn't notice that the
> pipe has closed.
Does not it get a SIGPIPE or something? Should not it? Thanks!
-mi
| |
| Barry Margolin 2007-12-19, 7:27 pm |
| In article < XaudnUcksMiNJ_TanZ2dnUVZ_gqdnZ2d@speakea
sy.net>,
Mikhail Teterin <usenet+mill@aldan.algebra.com> wrote:
> Barry Margolin wrote:
>
> Does not it get a SIGPIPE or something? Should not it? Thanks!
SIGPIPE occurs when you try to write to a pipe whose reading end has
closed. If you don't have anything to write, you don't get a signal.
That's why tail doesn't exit until something new is written to
/var/log/messages.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
|
|
|
|
|