Archive for July 15th, 2010

 

perl forking

Jul 15, 2010 in Notas rápidas, perl

Esquema de como montar forks con perl,

#!/usr/bin/perl

my $pid = fork();
my @childs ;

if ( not defined $pid ) {
    # error no se puede crear el forkç
    print " no es posible crear el fork ";
}

if ( $pid == 0 ) {
    # es un hijo

    # aqui lo que ejecuta el  hijo
    # aqui lo que ejecuta el hijo
   
    exit( 0 ) ;
   
} else {
    # padre , guardmos la lista de hijos para luego, matarlos
   
    push(@childs, $pid);
}

# matar los hijos
    foreach (@childs) {
    waitpid($_, 0);
    }