#!/usr/bin/perl use warnings; use strict; use threads; my $thr; for(1..10){ $thr = threads->new( \&sub1 )->detach; # Spawn the thread } while(1){ my $thread_count = threads->list(); print "\n\n\n\t\t",'num threads ', $thread_count, "\n\n\n"; print "Hit control c to exit \n\n\n\n"; sleep 1; } exit; sub sub1 { use Net::SSH2; # assuming a user named 'z' for demonstration # connecting to localhost, so you need your sshd running # see maillist archives at # http://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users # for deeper discussions my $self = threads->tid(); my $ssh2 = Net::SSH2->new(); $ssh2->connect('localhost') or die "Unable to connect Host $@ \n"; $ssh2->auth_password('z','ztester') or die "Unable to login $@ \n"; #shell use my $chan = $ssh2->channel(); $chan->blocking(0); $chan->shell(); print $chan "ls -la\n"; print "thread $self : $_" while <$chan>; print $chan "who\n"; print "thread $self : $_" while <$chan>; print $chan "date\n"; print "thread $self : $_" while <$chan>; $chan->close; }