0

This code can't be executed. Signal is sent to the function via signal, but the code inside the function is not running.

void my_sigtrap(int sig) {
    LOGD("mtf----   why not working  ");
} 

void test_signal() {//SIGTRAP
    signal(SIGTRAP, my_sigtrap);
}

why my_sigtrap function not working?

xxking
  • 77
  • 10
  • While inside a signal handler, there are restrictions on which functions that you can safely call. See e.g. https://stackoverflow.com/questions/16891019/how-to-avoid-using-printf-in-a-signal-handler – Michael Nov 05 '18 at 11:00

1 Answers1

2

The function signal() does not send the signal, but installs your own signal handler so when that signal is received your function will be executed to handle it. The signal is actually sent to the process using the kill() API (look up the details using man 2 kill).

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33