Catching signal inside its own handler

后端 未结 5 665
抹茶落季
抹茶落季 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:09

    Using the printf function within a signal handler is not exactly a good idea to use as it can cause behavior that is undefined! The code sample is missing a vital bit for the signal handler to work....Have a look at my blog about this here on 'Q6. How to trap a Segmentation fault?'

    Also, you need to replace the while loop with something more robust as a way to quit the program while testing the signal handler...like...how do you quit it?

提交回复
热议问题