I just responded to a similar post "Forking in NT" but... Use open2 or open3 to comunicate with child processes. If you're just coding for win32 then you may want to also look at the Win32 modules, especcially Process.pm and Event.pm. There are some examples in C:\Perl\site\lib\Win32. Below is a simple one I wrote. It was supposed to be simple but then it blew out of all proportion. Its a simple frame of a parent and child relationship where the parent launches a number of children and then they comunicate back and forth using pipes and Win32::Event. Email me if you need an explanation for anything thats going on there.
Does anyone know if there is a similar mechanism in Unix to Win32::Event? - Johnathan In parent.pl: #!/usr/bin/perl use strict; use IO::Handle; use IPC::Open2; use Win32::Event; autoflush STDOUT; my %child; for(my $i=0; $i<5; ++$i){ my $in = new IO::Handle; my $out = new IO::Handle; my $pid = open2($out,$in,"perl C:\\tmp\\child.pl"); print "LAUNCHED CHILD $i ($pid)\n"; $in->autoflush(); $in->print("YOU ARE NUMBER $i\n"); my $event; until($event){$event = Win32::Event->open("child_ready_$i")}; print "GOT EVENT FROM CHILD $i\n"; $event->wait(); my $message = readline($out); $message =~ s/\s+$//; print "CHILD $i SAID '$message'\n"; my $x = int(rand 5); $in->print("SLEEP $x SECONDS\n"); print "TOLD CHILD $i TO SLEEP FOR $x SECONDS\n"; $child{$pid} = {in=>$in,number=>$i,event=>$event,called=>1}; } while(%child) { my @active_pids = keys %child; my @events = map {$child{$_}->{event}} @active_pids; print "ACTIVE CHILDREN: ",join(',',sort(map {$child{$_}->{number}} @active_pids)),"\n"; my $active = Win32::Event::wait_any(@events); $active or die("Something odd happened"); if($active > 0){ my $pid = $active_pids[$active-1]; my $message = readline($child{$pid}->{out}); $message =~ s/\s+$//; print "child $child{$pid}->{number} said '$message'\n"; if($child{$pid}->{called} > 5){ $child{$pid}->{in}->print("EXIT\n"); print "TOLD CHILD $child{$pid}->{number} TO EXIT\n"; waitpid $pid, undef; print "CHILD $child{$pid}->{number} EXITED\n"; delete $child{$pid}; } else { my $x = int(rand 5); $child{$pid}->{in}->print("SLEEP $x SECONDS\n"); print "TOLD CHILD $child{$pid}->{number} TO SLEEP FOR $x SECONDS\n"; ++$child{$pid}->{called}; } } elsif($active == 0){ die("THIS CAN'T BE!!! I DID'T TELL IT TO TIME OUT!!!"); } else { my $pid = @active_pids[$active*-1 - 1]; print "CHILD $child{$pid}->{number} DIED!\n"; delete $child{$pid}; } } In child.pl: #!/usr/bin/perl use strict; use IO::Handle; use Win32::Event; autoflush STDOUT; my($number) = <STDIN> =~ /YOU ARE NUMBER (\d+)/; my $event = Win32::Event->new(0,1,"child_ready_$number"); print "entering command cycle\n"; while(my $command = <STDIN>){ chomp $command; last if($command eq 'EXIT'); if($command =~ /^SLEEP (\d+) SECONDS$/){ sleep $1; print "slept for $1 seconds\n"; $event->set(); } else { print "unknown command\n"; } } insomniak wrote: >(please forgive the dulpicate post - last one has wrong subject Doh!) >Hi All, > >I trying to find some information (examples) about forks or thread for perl >on win32, can anyone help me? > >Basically want to run 'X' simultanous processes in a continous loop. That is >there will alway be 'X' number of processes running. > >I thought I could do it with use Thread but I get back a message saying > This perl was built for "ithreads", which currently does not support >Thread.pm etc.... > >is there another/better way without using fork/threads? > >Thanks >Mark > > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]