>>>>> "Jas" == Jaswinder Singh Kohli <[EMAIL PROTECTED]> writes:
Jas> Hi,
Jas> Can you eXplain the use of this line in perl
Jas> $SIG{CHLD} = sub {wait ()};
Jas> what does this do.....
man perlipc
Sets the signal handler for SIGCHLD to an anonymous subroutine which
calls `wait' whenever the process receives a SIGCHLD. Prevents
creation of zombies.
Jas> this is used in an eXample for a fork call in perl...
Jas> and the main problem is this code , the program isn't
Jas> entering the accept() branch. Creates Socket and instead of
Jas> going thru the while loop goes to neXt statement in while
Jas> loop.
Works for me (sort of) if you add a Listen => 5 argument to the new
IO::Socket::INET invocation.
Jas> Code: Start
Jas> -----------------------------
Jas> use IO::Socket;
Jas> $SIG{CHLD} = sub {wait ()};
Jas> $mainSock = new IO::Socket::INET (LocalHost => 'localhost',
Jas> LocalPort => 5893,
Jas> Proto => 'tcp',
Jas> Reuse => 1
Jas> );
Jas> die "\nMain Socket could not be created. Reason: $!" unless $mainSock;
Jas> print "MAIN: Socket Creation succ\n";
Jas> while ($msgSock = $mainSock->accept())
Jas> {
Jas> print "Inside Accept";
Jas> if(!defined($child_pid = fork()))
Jas> {
Jas> die "\nCannot fork: $!";
Jas> }
Jas> if($child_pid == 0)
Jas> {
Jas> # After fork the return val. of child is 0
Jas> forkedChild($msgSock);
Jas> exit(0);
Jas> }
Jas> }
Jas> print "MAIN: End of Program\n";
Jas> sub forkedChild
Jas> {
Jas> $msgSock = $_[0];
Jas> while(defined($buffer = $msgSock->get_line()))
Jas> {
Jas> print $buffer;
Jas> }
Jas> }
Jas> ------------------------------------------
Jas> Code: END
Regards,
-- Raju
--
Raju Mathur [EMAIL PROTECTED] http://kandalaya.org/
It is the mind that moves
================================================
To unsubscribe, send email to [EMAIL PROTECTED] with unsubscribe in subject
header. Check archives at http://www.mail-archive.com/ilugd%40wpaa.org