Voila, j'ai trouvé mon bonheur via GoogleSupport :)
Le petit script suivant fait tout le nécessaire (ca pourra peut-etre vous être
utile aussi)
#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw/WNOHANG/;
my @kids = ();
for my $i (0..9)
{
my $kid = fork;
if (not defined $kid)
{
die "Fork failed - $!\n" unless $! =~ /No more process/;
sleep(5);
redo;
} elsif ($kid)
{
# Parent - store kid ID in list
$kids[$i] = $kid;
} else
{
# Child
my $s = int(rand(30));
print "Sleeping for " . $s . " seconds...\n";
sleep($s);
print "Child $i done!\n";
CORE::exit;
}
}
while (scalar(@kids))
{
my $i = 0;
for my $k (@kids)
{
if (waitpid($k, WNOHANG))
{
# Child has been reaped.
print "Child $i has been reaped!\n";
@kids = grep {$_ != $k} @kids;
}
++$i;
}
}
Xavier
--
If Bill Gates had a dime for every time a Windows box crashed...
..Oh, wait a minute, he already does.
On Tue, 7 Mar 2006, Thomas Silvestre wrote:
> Le 07/03/06, Xavier Mertens<[EMAIL PROTECTED]> a écrit :
> > Bonjour à tous,
> >
> > J'ai un problème bizarre avec un script Perl qui se fork().
> > Afin d'augmenter les performances, j'ai un fichier à processer et à
> > transferrer par FTP vers divers destinations.
> >
> > Donc, je crée un process par destination via fork(). Finalement, j'efface
> > le fichier source.
> >
> > Le problème, c'est que certains sous-process n'ont pas le temps d'accèder
> > au fichier, il est effacés AVANT.
> >
> > Qqn a une méthode safe pour gérer ce genre de problème?
> > Ex: attendre que tous les processes "forkés" soit terminés?
> >
> > Xavier
> > --
> > Free shell account on www.rootshell.be!
> >
>
> j'ai jeté un oeil dans la man de fork pour perl (perlfork pour la
> nommer) et ils parlent de wait(), c'est peut-être une voie à explorer?
>
> --
>
> Thomas Silvestre
> _______________________________________________________
> Linux Mailing List - http://www.unixtech.be
> Subscribe/Unsubscribe: http://lists.unixtech.be/cgi-bin/mailman/listinfo/linux
> Archives: http://www.mail-archive.com/[email protected]
> IRC: chat.unixtech.be:6667 - #unixtech
> NNTP: news.gname.org - gmane.org.user-groups.linux.unixtech
> _______________________________________________________
Linux Mailing List - http://www.unixtech.be
Subscribe/Unsubscribe: http://lists.unixtech.be/cgi-bin/mailman/listinfo/linux
Archives: http://www.mail-archive.com/[email protected]
IRC: chat.unixtech.be:6667 - #unixtech
NNTP: news.gname.org - gmane.org.user-groups.linux.unixtech