- 論壇徽章:
- 1
|
我的作法...從network programming with perl改的..
- # create a pipe for IPC
- pipe(CHILD_READ,CHILD_WRITE) or die "Can't make pipe!\n";
- #-- Parent Process maintain read the input of child
- my $IN = IO::Select->new(\*CHILD_READ);
- $SIG{CHLD} = \&reap_child;
- while(!$DONE){
- if($IN->can_read){ # get a message from one of the children
- my $message;
- next unless sysread(CHILD_READ,$message,4096);
- my @messages = split /\n/,$message;
- foreach (@messages){
- next unless my ($pid,$status) = /^(\d+) (.+)$/;
- if($status ne 'done'){
- $STATUS{$pid} = $status;
- }else{
- delete $STATUS{$pid};
- }
- }
- }
- print join(" ",map {"$_ => $STATUS{$_}"} keys %STATUS )."\n";
- #----- do nothing,if no child alive, -----
- unless(%CHILDREN){
- $normal = 1;
- last;
- }
- }
- ##-------假如非正常結(jié)束,必須刪除所有子程序
- if($normal ==0){ kill_children(); exit 1;}
復(fù)制代碼 |
|