Hi Monks, This is Srinivas, a beginner in Perl.

I was trying to connect to remote system by using Net::SSH::Perl module . I have installed all the required modules for this module to work and tried my hand on writing a small script by embeding it in multi threads. Here is the code

#!/usr/bin/perl use Net::SSH::Perl; use threads; $filepath="/tmp/Perl/host.conf"; if(open(FILE, $filepath)) { $inputline=<FILE>; while($inputline ne "") { chomp($inputline); if($inputline !~ /#/) { if( @array = split(/:/,$inputline) ) { $host = $array[1]; $user = $array[2]; $pass = $array[3]; print "\n\n\n ------ CHECK1 $user $host $pass +\n\n\n\n\n "; push @threads, threads->create(\&method, $host +, $user, $pass); } #if2 } #if1 $inputline=<FILE>; } #while while ( my $thread = shift @threads ) { $thread->join ; print " Thread [ $host ] Ending ... \n"; } } else { die " File doesn't exists " } sub method { my($hst,$usr,$pas)=(shift,shift,shift); &thrds($hst, $usr, $pas); } sub thrds { my($h,$u,$p)=(shift,shift,shift); $ssh = Net::SSH::Perl->new($h,debug=>'true'); $ssh->login($u,$p); my($stdout, $stderr, $exit) = $ssh->cmd('hostname'); my($stdout, $stderr, $exit) = $ssh->cmd('ls -l'); print $stdout; $ssh->close(); }
When I execute the above code with only two threads, the CPU is going upto 100% and system is getting hanged. My ram size is appriximately 4GB. I have no problem with a single thread or when executed without threads.

Did I mis-configured any thing. Please help me.

Thanks in advance,

Srinivas.


In reply to Problem with threads in Net::SSH:Perl by Anonymous Monk

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.