- 论坛徽章:
- 0
|
回复 11# toniz
发现windows下的fork和waitpid与unix下的差别很大,估计实现细节不同。比如下面的代码:- use POSIX ":sys_wait_h";
- my %children;
- my $count = 0;
- $SIG{CHLD} = sub {
- while ((my $pid = waitpid(-1, WNOHANG)) > 0) {
- if ($children{$pid}) {
- delete $children{$pid};
- $count--;
- print "$pid reaped. count is $count.\n";
- }
- }
- };
- my $num = 0;
- while ($num++ < 34) {
- my $pid = fork();
- until (defined $pid) {
- print "Failed to fork, num is $num, count is $count, try to reap zombies.\n";
- sleep 5 if $count;
- print "Zombies reaped, count is $count, try to fork again.\n";
- $pid = fork();
- }
- $children{$pid} = 1;
-
- if ($pid == 0) {
- sleep 5;
- exit 0;
- }
- $count++;
- }
- $num = 0;
- while ($count) {
- $num++; print "sleep 50. num is $num, count is $count.\t";
- sleep 50;
- }
复制代码 在windows下竟然无法正常收割,unix下则可以。 |
|