in reply to Re: creating multiple instances of a process
in thread creating multiple instances of a process

Sorry for the delay in responding, but I've been banging my head against this for awhile. I've tried what I believe'd is what you were telling me, but I'm a little dense. The system I'm on is redhat if that helps. Here is my ammended code after your suggestions, let me know what you think.
#!/usr/bin/perl -w use strict; chomp (my $curdir = `pwd`); my $proc = '../delme.pl > proc.log 2>error.log'; my %kid; for (1 .. 4) { chdir $curdir; do { mkdir "test$_" or die $! } unless (-d "test$_"); chdir "test$_" or die $!; print "Launching: Process $_$/"; defined(my $cpid = fork) or warn $! and next; $kid{$cpid} = undef, next if %kid; exec $proc; exit 0; } delete $kid{wait()} while %kid; print "Done...$/";
I get no errors but only one instance runs. I need four independant instances running and as you can see by code they should each run in their own directory. The delme.pl is trivial, essentially just printing a line to STDOUT as well as STDERR, then sleeping for 25 seconds.

Thanks for your help!

Sweetblood

Replies are listed 'Best First'.
Re^3: creating multiple instances of a process
by Zaxo (Archbishop) on Jun 20, 2005 at 18:32 UTC

    You have a typo in line 14 which is making both the parent and child run the child code and exit on the first time through the loop. Change . . . if %kid; to . . . if $cpid;.

    After Compline,
    Zaxo

      Indeed! That was the problem, Many Thanks!

      Sweetblood