title: How can I call a method in a running Perl process from another process?
body: <p>Ok, so, I got the signal through but for some reason the process exists after it receives the signal. </p>
  
  <p>If I add an endless loop (while(1) ) before I even create the socket then it works as prescribed. 
  So... something in my socket code is quitting when the kill command is issued. </p>
  
  <p>I don't see what it would be though. Without the kill, the process sits there indefinitely accepting connections and sending messages to the clients. Why would the kill (and the incrementation of the variable that follows) provoke the socket to get out of it's loop and let the process end?</p>
  
  <p>The socket code is beneath...</p>
  
  <p>[EDITED again]</p>
  
  <pre><code>$SIGNAL = 0;
          sub sigHandler{ 
              #&amp;logData("SIGNALED");
              $SIGNAL++ ;
          }
          $SIG{"USR1"}=\&amp;sigHandler;
  
  
  
          # Create a new socket, on port 9999
          my $PORT = 9999;
          print ("opening connection on port $PORT");
          $lsn = new IO::Socket::INET(Listen =&gt; 1, 
                                      LocalPort =&gt; $PORT,
                                      Reuse =&gt; 1,
                                      Proto =&gt; 'tcp' );
             #or die ("Couldn't start server: $!");
  
  
  
          # Create an IO::Select handler
          $sel = new IO::Select( $lsn );
  
          # Close filehandles
  
          close(STDIN); close(STDOUT);
  
          warn "Server ready.  Waiting for connections . . .  on \n";
  
  
          # Enter into while loop, listening to the handles that are available.
          # this SHOULD be an infinite loop... I don't see why it would eval to false when 
          # I send a signal to increment $SIGNAL by one.
          while( @read_ready = $sel-&gt;can_read ) {
              $MESSAGE = 0;
              $fh  = $read_ready[0];
  
                  # Create a new socket
                  if($fh == $lsn) {
                      $new = $lsn-&gt;accept;
                      $sel-&gt;add($new);
                      push( @data, fileno($new) . " has joined.");
                      warn "Connection from " . $new-&gt;peerhost . ".\n";
  
                  }
  
                  # Handle connection
                  else {
  
                      $input = &lt;$fh&gt;;
                      chomp $input;
                      warn "GOT INPUT '$input'\n";
  
                      if($input eq "&lt;policy-file-request/&gt;"){
                          $MESSAGE = 
                              qq~&lt;?xml version="1.0"?&gt;
                              &lt;cross-domain-policy&gt;
                                &lt;allow-access-from domain="*" to-ports="*"/&gt;
                              &lt;/cross-domain-policy&gt;\0~;
                          $SIGNAL++;
                      }
  
  
                      if ( $input eq '') {#disconnection notification by client
  
                          warn "Disconnection from " . $new-&gt;peerhost . ".\n";                
                          $sel-&gt;remove($fh);
                          $fh-&gt;close;
                      }
                      if ( $input eq 'READY'){
                          warn "CLIENT READY = 1\n";
                          $CLIENT_READY = 1;
                      }
  
                  }
  
  
  
              # Write to the clients that are available
              foreach $fh ( @write_ready = $sel-&gt;can_write(0) ) {
                  if($MESSAGE == 0){
                      #set message here based on criteria
                      $MESSAGE = "UPDATE";
                  }
                  warn "outside send if\n";
                  if($CLIENT_READY == 1 &amp;&amp; $SIGNAL &gt; 0){
                      warn ("sending $MESSAGE to $fh\n");         
                      $CLIENT_READY = 0;          
                      $SIGNAL--;
                      print $fh "$MESSAGE\0" or warn "can't send message to $fh";  
                  }             
              }
          }
  
  
          warn "Server ended.\n";
  </code></pre>