Perl en Español

  1. Home
  2. Tutoriales
  3. Foro
  4. Artículos
  5. Donativos
  6. Publicidad
 

Duda teórica y puntual de signals en un daemon Perl

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Experto
Mensaje Mar Jul 01, 2008 3:40 pm
monoswim
Vive para Perl en Español
Vive para Perl en Español
Registrado: 18 Nov 2003
Mensajes: 716
Ubicación: Buenos Aires
Duda teórica y puntual de signals en un daemon Perl Responder citando

Hola, tengo un daemon HTTP hecho en Perl que funciona de 10... pero hay algo que funciona bien y no se por qué Confused Se las hago fácil:

Creo un server con my $server = IO::Socket::INET->new(...)

Tengo un bucle para las conexiones while ($client = $server->accept()){...}continue{} que las trata con FORK...

Y luego del bucle coloco el código para cuando se termine (que pensaba controlar con una variable escalar que cambiara de valor al capturar algún SIGNAL, lo cual NO FUE NECESARIO)

Cuando le tiro un SIGNAL 2 (int) automáticamente sale del bucle y ejecuta el código que viene luego del while... SIN QUE SE LO MARQUE YO...

¿Es normal esto? ¿Que un kill(2, $pid) corte el bucle? ¿Elimina la conexión al socket de $server? ¿Cómo es que el bucle se corta?

Desde ya muchas gracias... Sé que no es fácil de contestar... jeje... tampoco es vital... funcionar funciona... y muy bien... Smile

Saludos
Mensaje Mar Jul 01, 2008 4:42 pm
explorer
Moderador
Moderador
Registrado: 24 Jul 2005
Mensajes: 4105
Ubicación: Valladolid, España
Responder citando

Creo que lo pone en

http://perldoc.perl.org/perlipc.html#Internet-TCP-Clients-and-Servers

Cita:
If accept() is interrupted by a signal then $! will be set to EINTR. If this happens then we can safely continue to the next iteration of the loop and another call to accept(). It is important that your signal handling code doesn't modify the value of $! or this test will most likely fail. In the REAPER subroutine we create a local version of $! before calling waitpid(). When waitpid() sets $! to ECHILD (as it inevitably does when it has no more children waiting), it will update the local copy leaving the original unchanged.
Mensaje Mie Jul 02, 2008 7:15 am
monoswim
Vive para Perl en Español
Vive para Perl en Español
Registrado: 18 Nov 2003
Mensajes: 716
Ubicación: Buenos Aires
Responder citando

Pero esto está hablando del hijo, la función REAPER y waitpid es para que salga del hijo y el padre siga en otra iteración...

Yo hablo de salir del padre... para detener el servicio...

Saludos
Publicar nuevo tema   Responder al tema    Foros de discusión -> Experto Todas las horas son GMT - 6 Horas
Página 1 de 1



Powered by phpBB © 2001, 2005 phpBB Group