You might try using an arp ping instead of your more complicated setup. The arping utility does this. arping sends pings over ethernet asking "which mac address owns this ip address". This would eliminate the complicated step of running tcpdump.

Edit: arping would only work if your VMs are on the local network. This might be a silly assumption for me to make what with cloud computing and all. If your VMs aren't on the local network I would suggest using a piped open and select and maybe using Net::Ping instead of the ping command.

Here is a test I created for my own curiosity. The summary of my findings are:

Rather confusing. So basically, if you insist on using threads detach the thread after you set the alarm handler and alarm delay in the parent thread. This is kind of silly because you could detach the thread and just sleep, then kill the thread or whatever.

Lose the threads, lose tcpdump and ping, and use: `arping -c 1 $host`. Easy.

#!/usr/bin/perl use warnings; use strict; use threads; sub set_alarm { $SIG{'ALRM'} = sub { printf "Alarm went off in thread #%d\n", threads->tid(); print qq{"Get up, get up!", says the clock.\n}; exit 1; }; alarm shift; } # If you set the SIGALRM handler HERE and ... # If you join the thread, the alarm handler goes off after 10 se +conds # ( The 'sleep' delay set inside the child thread. ) # If you detach the thread, the alarm handler goes off after 3 sec +onds # ( The 'alarm' delay set inside the thread ) # Or If you don't set 'alarm' inside the thread, the outer 'al +arm' # delay is used. set_alarm( 5 ); my $sleepy = threads->create ( sub { # If the SIGALRM handler is used in + this thread # (comment out the set_alarm above) # it simply prints "Alarm clock" ! +hahahaha set_alarm( 3 ); sleep 10; print "Well, well, are you joining +me in bed?\n"; } ); printf "Main thread # is %d.\nChild thread # is %d.\n", threads->tid(), $sleepy->tid(); # Try commenting out detach/sleep and uncommenting join # $sleepy->join; $sleepy->detach; sleep 15; # you only need to sleep when detach-ing print "*Fart*\n"; # Luckily this never gets reached... print "Oh crap I'm late for work!\n";

Edit: To be clearer, SIGALRM handlers inside the child thread are apparently never reached. I also only ran this on Mac OS X, who knows you could get different results on different machines (Joy!).


In reply to Re: Threads, bash, and networking by juster
in thread Threads, bash, and networking by morganda

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.