I have the following code:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_t test_thread;
void *thread_test_run (void *v)
{
int i=1;
while(1)
{
printf("into thread %d\r\n",i);
i++;
sleep(1);
}
return NULL
}
int main()
{
pthread_create(&test_thread, NULL, &thread_test_run, NULL);
sleep (20);
pthread_cancel(test_thread);
sleep(100);
// In this period (before the finish of myprogram),
// I execute killall to kill myprogram
// I want to add a signal handle function to
// execute pthread_exit() before the program quit
}
I want to complete my code by adding a signal handle function to execute pthread_exit() before the program quit.
How to do it ?
Because
killall
sends the signalSIGTERM
by default, you can handle this type of signal.This is how I implement some sort of what you want in my utilite https://github.com/seriyps/wrk/commit/1d3c5dda0d46f0e567f3bae793bb3ae182de9438