Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > Terminating a t...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 4035 of 4146
Post > Topic >>

Terminating a threaded program using signals

by "lancer6238@[EMAIL PROTECTED] " <lancer6238@[EMAIL PROTECTED] > Sep 19, 2008 at 01:23 AM

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
 




 8 Posts in Topic:
Terminating a threaded program using signals
"lancer6238@[EMAIL P  2008-09-19 01:23:22 
Re: Terminating a threaded program using signals
"SJBartnikowski@[EMA  2008-09-19 07:04:10 
Re: Terminating a threaded program using signals
Markus Elfring <Markus  2008-09-20 12:10:35 
Re: Terminating a threaded program using signals
Markus Elfring <Markus  2008-09-20 13:17:12 
Re: Terminating a threaded program using signals
"lancer6238@[EMAIL P  2008-09-21 17:41:37 
Re: Terminating a threaded program using signals
Markus Elfring <Markus  2008-09-22 14:11:37 
Re: Terminating a threaded program using signals
"lancer6238@[EMAIL P  2008-09-22 17:38:15 
Re: Terminating a threaded program using signals
Markus Elfring <Markus  2008-09-23 10:25:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 8:17:08 CST 2008.