Hello Monks,

I have used Perl threading in quite a few scripts, but I'm banging my head against a wall with this issue. What happens is, the output gets mangled up and breaks the Bash term (which I then need to reset in many cases). The lock is indeed working (as far as keeping multiple threads from printing out at once). I have narrowed down the problem to the ssh/tcpdump line. Without this line, I can output anything and there are no issues. With this line, I can literally print anything after the lock and the output will get mangled up 50% of the time. Specifically, the output appears to indent further every line. If I print entire packets every packet line is further indented. After the script is done running the Bash term is all screwed up, sometimes newlines don't process, and sometimes the text is invisible.

use threads; use threads::shared; my $lock:shared; foreach my $server (@servers) { chomp $server; push (@threads, threads->create (\&dumpServer, $server)); } foreach (@threads) { $_->join(); } sub dumpServer { my $server = shift; my $net = `ssh -tt $server '/usr/local/bin/tcpdump -c10 -nntttt port + 80 2>/dev/null' 2>/dev/null`; ## This is the line that causes the i +ssue lock($lock); print "TEST - $server\n"; ## Want to print $net output here, but pr +inting even a simple string gives me the issue }
Example Output:
TEST - Server1 TEST - Server2 TEST - Server3 TEST - Server4 Bash Prompt (now need to reset term)
Thanks for your time.

In reply to Threads Printing Issue - Output Mangled / Term Crashing by bigbot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.