Catching signal inside its own handler

后端 未结 5 696
抹茶落季
抹茶落季 2021-01-11 10:41
#include
#include

void handler(int signo)
{
    printf(\"Into handler\\n\");
    while(1);
}
int main()
{
    struct sigaction act;
          


        
5条回答
  •  遥遥无期
    2021-01-11 11:25

    You can use something like this instead of printf:

    const char *str = "Into handler\n";
    write(1, str, strlen(str));
    

    The function write(..) is safe to be called from signal hanlder. Don't forget to include unistd.h header to use it.

提交回复
热议问题