How to execute a handler function before quit the program when receiving kill signal from“killall” or “kill -p pid”?

后端 未结 2 925
我寻月下人不归
我寻月下人不归 2021-01-24 19:45

I have the following code:

#include 
#include 
#include 

pthread_t test_thread;

void *thread_test_run (void *v)         


        
2条回答
  •  不知归路
    2021-01-24 20:01

    Because killall sends the signal SIGTERM by default, you can handle this type of signal.

    #include 
    
    void handler(int sig)
    {
         /* ... */
    }
    
    signal (SIGTERM, handler);
    

提交回复
热议问题