限制perl多进程数量
发布时间:2020-12-16 00:36:45 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perluse strict;use warnings;use POSIX ":sys_wait_h";my $maxproc = 4;my $zombies = 0;$SIG{CHLD} = sub { $zombies++ };for my $item (1 .. 10){ my $pid = fork(); if (!defined $pid) { print "Error!n"; exit 1; } if ($pid == 0) { prin
#!/usr/bin/perl use strict; use warnings; use POSIX ":sys_wait_h"; my $maxproc = 4; my $zombies = 0; $SIG{CHLD} = sub { $zombies++ }; for my $item (1 .. 10) { my $pid = fork(); if (!defined $pid) { print "Error!n"; exit 1; } if ($pid == 0) { print "child $item : my pid = $n"; sleep 5; print "child $item : endn"; exit; } while (`ps -ef | grep $0 | wc -l` > $maxproc) { print "greate maxchild numn"; sleep 1; } if ($zombies > 0) { while ((my $collect = waitpid(-1,WNOHANG)) > 0) { $zombies--; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |