Re: Executing System Program

Greg Meckes <[email protected]> Tue, 18 Dec 2007 18:45:53 -0800 (PST)
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
thanks Chris. Fork is confusing to me. How can I execute the following using fork?


-----SNIP

opendir (DIR,"/somedir") or die "Couldn't open somedir: $!\n"; 
my @list  = grep (!/^\.\.?$/, readdir(DIR));
closedir(DIR);


foreach my $dir (@list) {

    #Spawn this tar command, then continue.
    #Don't wait for it to finish.
    #Go immediately to the next one and 
    # spawn another process of tar - as many as needed.
    
    my @args = ("tar -cvf $dir");
    exec @args or print STDERR "Couldn't exec tar -cvf $dir: $!";

}

--- END SNIP

If I were to run this manually I would say:

$>tar -cvf /dir1 &
$>tar -cvf /dir2 &
$>tar -cvf /dir3 &

Then  I would see (for example):

$>ps -eaf | grep tar
root      3647     1  0 Dec12 ?        00:01:13 /bin/tar -cvf /dir1
root      3678     1  0 Dec12 ?        00:00:14 /bin/tar -cvf /dir2
root      3681     1  0 Dec12 ?        00:00:26 /bin/tar -cvf /dir3

How can I do this?






--- "Wagner, Chris (GEAE, CBTS)" <[email protected]> wrote:

> I would go with the good old fork() and exec() method.
> e.g.
> if (fork()) {
> 1;
> }
> else {
> exec("do something");
> }
> 
> Greg Meckes wrote:
> > 
> > Greetings, I have the following task:
> > 
> > I have to run a Perl script to run spawn multiple processes on a Linux server. The issue is
> that
> > each process is huge and may take a while to run.
> > 
> > I simply want my program to run, then start process 1 and let it run in the background, then
> > immediately start process 2 etc.
> 
> 
> -- 
> Chris Wagner
> CBTS
> GE Aircraft Engines
> [email protected]
> 


-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]