Hi all,
I'm writing a program using Pthreads, and I am looking for a way to
correctly terminate the program using signals.
Say I have 5 threads + 1 main thread running. I have the main thread
running pcap_loop and the other 5 threads processing the packets. At
some point, I want to terminate the program by pressing Ctrl-C. I have
the following:
signal(SIGINT, terminate_process);
where terminate_process(int sig) is the function I want to run when
the program terminates.
I have a series of statements, which are correctly printed after I
press Ctrl-C, but then the program just hangs there. If I press Ctrl-C
again get the error "*** glibc detected *** ./a.out: double free or
corruption (!prev): 0x000000000098abd10 ***"
Here is my terminate_process function:
void terminate_process(int sig)
{
/* several printf statements */
pcap_breakloop(handle);
pcap_close(handle);
}
"handle" is a global variable. My question is how to I correctly
terminate the program?
Thank you.
Regards,
Rayne


|