Hi all, Not sure if this appropriate for the beginners list but there is no intermediate list :)
I am writing a program in Perl to 'move' output from one process. The program looks in a database which contains lists of files. These files are either FTP'ed to mailed to recipients. I actually made this program using modules Mime::Lite and Net::FTP No sweat really. But when I FTP or mail, the program waits, so I want to make it multi process. And there is my problem. I tried fork() but it doesn't do what I want or I got it wrong. (maybe it's not the appropriate thing to use anyway) So my question is: how to start multi processing? Just imagine I have 'datapump', I gathered all data required to send it. What I want now is that a separate process is started to send the file (either by FTP or mail). The data pump continues and spawns up to 10 processes, if more it will wait. Here is what I thought would work: (try program) #!/bin/env perl use strict; my $ADD = 0; my $WAIT = 1; { my $state = $ADD; my $processes = 1; sub ProcessHandler { my $request = @_; print "REQUEST = $request STATE = $state PRC = $processes\n"; if ($state == $ADD) { my $pid = fork(); die "Cannot fork: $!" unless defined($pid); if ($pid == 0) { # Child process $processes++; if ($state > 10) { $state = $WAIT; } sleep (int(rand 20) + 1); print "child proc added PRC = $processes\n"; } else { print "MAIN process PRC $processes\n"; } } elsif ($state == $WAIT) { print "WAIT\n"; wait; $state = $ADD; $processes--; print "child proc removed PRC = $processes\n"; } } } my $i; for ($i = 0;; $i < 20; $i++) { print "HI! $i\n"; ProcessHandler($i); }; It doesn't do what I want at all. It spawns way too many processes. (and I get errors in win 2000). Basically, I want to spawn a process which does something (call a subroutine) The main process should just continue pumping data which is spawned up to 10 processes. Else it should wait until 1 of the 10 processes finishes. Any code examples out there?? PS The target machine is a Unix box. Thanx, Jeroen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]