I can't explain the behavior you're observing, but the code you posted is incorrect. You are separating out the two selects, which means it won't check for socket output until it gets tail output, and once it does, it won't check for tail output until it gets socket output. You need to combine them together, and when select returns you have to figure out whether it's the pipe from tail or the socket that has data available.
As for the problem of your tail dying, I suggest you sprinkle salt on it once a week and be careful how you sit down. No, wait, that's wrong. I meant to say that I suspect the tail would fail even if you ran it from the command line -- either because that file doesn't exist, or because your version of tail doesn't support the command-line arguments you're passing it. If you want to tail -f a file that might not exist yet, use tail -F (for GNU tail, at least). If I'm wrong and the cause of death is more mysterious, try either changing "tail -f -n 0 /tmp/test_file |" to "tail -f -n 0 /tmp/test_file 2>&1 | tee /tmp/unhappy.log |", or to "strace -o /tmp/unhappier.log tail -f -n 0 /tmp/test_file". Examine the generated log file to diagnose the problem.
Once you merge the two selects, you can dispense with the timeout too.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.