免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3700 | 回复: 2
打印 上一主题 下一主题

谁能简介一下perl ithreads how to 控制进程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-14 20:04 |只看该作者 |倒序浏览
我写了一个perl 多进程程序,但是不能控制进程数目。
#!/usr/bin/perl

#代理验证小程序
use warnings;
use strict;
use threads;
use threads::shared;
my $k: shared = -1;
use LWP::UserAgent;
use vars qw( %config );
%config = ( MaxLength =>; 1*1024, # fetch file max 1K
RequestTimeOut =>; 30, # set timeout to 30s

);
#my $file=shift @ARGV;
my $file="verygood.txt";
my @ip;
open (OUTPUT,"$file"||die "could not open file";
while (<OUTPUT>{
push @ip,$_;
}

#my $ip="169.237.37.2:80";
#my $url="http://www.whatismyip.com/";
open (GOODIP,">;>;goodproxyip.txt";
my $url="http://www.edpsciences.com/htbin/ipaddress";
my $thr1;
my $thr2;
my $thr3;
my $thr4;
my $thr5;
while($k<@ip){
#$thr1 = threads->;new(\&amp;checkproxy,$ip[$k]);
$thr2 = threads->;new(\&amp;checkproxy,$ip[++$k]);
$thr2 = threads->;new(\&amp;checkproxy,$ip[++$k]);
$thr2 = threads->;new(\&amp;checkproxy,$ip[++$k]);
$thr2 = threads->;new(\&amp;checkproxy,$ip[++$k]);
$thr2 = threads->;new(\&amp;checkproxy,$ip[++$k]);
#$k++;
#$thr->;detach;
$thr2->;join;
}
# $thr1->;detach;




sub checkproxy{
my $ip=shift @_;
print "now check $ip\n";
my $ua=new LWP::UserAgent;
$ua->;agent("Mozilla/8.0";
$ua->;timeout( $config{RequestTimeOut} );
$ua->;max_size( $config{MaxLength} );
my $request=new HTTP::Request ('GET'=>;$url);
$ua->;proxy(['http', 'ftp'], "http://$ip/";
#$request->;header('Accept'=>;'text/html');
#$request->;header('Accept'=>;'text/plain');
my $response=$ua->;request($request);
if ($response->;is_success){
my $content=$response->;content;
print $ip."\n";
print GOODIP $ip."head\n";
if ($content=~/Your IP address is/i){
print GOODIP $ip."\n";
}

print $content;
}
}

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
2 [报告]
发表于 2003-03-15 11:09 |只看该作者

谁能简介一下perl ithreads how to 控制进程

用array取代thr1,thr2,thr3.....
perl的array可以隨時增加...只要限定
@array不要太大就好了...
MultiThread..我幾乎沒用過...

论坛徽章:
0
3 [报告]
发表于 2003-03-15 12:44 |只看该作者

谁能简介一下perl ithreads how to 控制进程

好象还可以通过循环次数来控制thread数目
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP