1

I have the following code in my perl script which somehow doesn't seem to work:

my $thr;

sub start__server_thread()
{
        $thr = threads->create(\&iperf_start_server, $_[0], $_[1], $_[2]);
        print("Value of thread is $thr\n");
        &START_SERVER_RESPONSE($controller_ip, $controller_port, "success", 2345, $_[1]);
}

sub iperf_start_server()
{
# Do some stuff here and then handle the signal
$SIG{'SIGSTOP'} = sub {
        print("Stop signal received\n");
        $thr->exit();
        $flag = 1;
        };
}

sub stop_server()
{
        my ($dat,$filelog,$result);
        $thr->kill('STOP');
        $flag = 1;
        sleep(10);
        $thr->exit(1);
}

When from some other context stop_server() is called, it tries to send the SIGSTOP signal to the thread. It is at this point that the execution stops and I get the error "Signal SIGSTOP received, but no signal handler set in perl script. Where have i gone wrong?

pilcrow
  • 56,591
  • 13
  • 94
  • 135
Daylite
  • 499
  • 1
  • 7
  • 19
  • 1
    [Don't use prototypes](http://stackoverflow.com/questions/297034/why-are-perl-5s-function-prototypes-bad) -- declare Perl subs as `sub name { ... }` not `sub name() { ... }`. – mob Jul 30 '13 at 17:32
  • What platform are you running this on? I think your problem is that you cannot trap the `STOP` or `KILL` signals. – chrsblck Jul 30 '13 at 18:02
  • I am trying the above code on Linux – Daylite Jul 31 '13 at 04:38

1 Answers1

1

You should be setting $SIG{STOP}, not $SIG{SIGSTOP}.

If you use warnings, you would have been alerted to this error. And if you use diagnostics, you would get some practical advice on what caused the error and how to fix it.

mob
  • 117,087
  • 18
  • 149
  • 283