why multiple SIGINT raises when i hit C-c

Thread Tools Search this Thread
Top Forums Programming why multiple SIGINT raises when i hit C-c
# 1  
Old 09-27-2009
why multiple SIGINT raises when i hit C-c


in my application, i have set up to capture SIGINT and execute a handler.the problem is whenever i hit C-c, multiple SIGINT are sent to the application.I have blocked the SIGINT right after catching the first one but it is unsuccessful.Here is what i do :

jmp_buf main_loop;

int main()


sigset_t set;
sigset_t old_set;


sigaddset (&set, SIGINT);

// run other threads ...

while( 1 )
if ( setjmp (main_loop) )
/// Clean up and shut down threads

return 0;


void CleanExit()
shutdownThreads = 1;
longjmp (main_loop, 1);

The problem is the CleanExit method runs 3 to 4 times which means the pthread_sigmask(SIG_BLOCK,&set,&old_set); has not done the job.

So what is the problem?

My application is running in mulinux.

Thanks in advance,
# 2  
Old 09-27-2009
Humm, the generally accepted way to handle a signal such as Ctrl-C in a threaded application is to create a specific signal handling thread which waits for a Ctrl-C and then sets a mutex or condition variable which the other threads check on a regular basis.

See Section 6.6 of Programming with POSIX Threads by Dave Butenhof. He provides example code for exactly what you are looking to do on starting on page 228. You can also find other examples if you do a web search.

By the way, it is bad practice to use setjmp and longjmp in threaded applications. Some versions of threads libraries actually use setjmp/longjmp internally for various purposes.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Hit multiple URL from a text file and store result in other test file

Hi, I have a problem where i have to hit multiple URL that are stored in a text file (input.txt) and save their output in different text file (output.txt) somewhat like : cat input.txt (3 Replies)
Discussion started by: mukulverma2408
3 Replies

2. Shell Programming and Scripting

Always pass SIGINT in ksh

The following command will run and wait for input from the user. /usr/sap/SAP/webdisp/wdispmon pf=/usr/sap/SAP/webdisp/profile What I would like to do is (in one command): - Add the above line to a ksh script - Receive the output - and send a SIGINT I have seen many posts on how to... (3 Replies)
Discussion started by: sapsid
3 Replies

3. UNIX for Dummies Questions & Answers

SIGINT issue

May i know what are the possible causes for SIGINT other than ctrl-c? Thanks (17 Replies)
Discussion started by: pandeesh
17 Replies

4. Shell Programming and Scripting

Trapping SIGINT after restarting program.

Tried to add a function to my control_c interrupt here. It works but has one little bug. If the user selects to run the function instead of exiting, the program restarts itself without forking as it should. However, after that control_c no longer works again. I wanted to allow the user to run... (1 Reply)
Discussion started by: Azrael
1 Replies

5. Shell Programming and Scripting

Intercepting SIGINT in a bash script

I've written a bash script which captures video with DVgrab. Because of the nature of the tapes that I am digitizing, sometimes I want to quit capturing before the time that I set for DVgrab. When this is the case I press Ctrl-c and DVgrab exits cleanly, my problem is that there is additional... (5 Replies)
Discussion started by: Starcast
5 Replies

6. Programming

[C] fgets problem with SIGINT singlal!!!

Hi all, I have this method to read a string from a STDIN: void readLine(char* inputBuffer){ fgets (inputBuffer, MAX_LINE, stdin); fflush(stdin); /* remove '\n' char from string */ if(strlen(inputBuffer) != 0) inputBuffer = '\0'; } All work fine but if i... (1 Reply)
Discussion started by: hurricane86
1 Replies

7. Programming

Problem with handling SIGINT

For a program I am designing, which involves handling the keyboard input Ctrl^c (SIGINT), it is taking ages for the program to actually recognise and perform the corresponding action whenever I run it and hit Ctrl^C at the CL. I have to do at least 3 Ctrl^Cs before the program will actually... (3 Replies)
Discussion started by: JamesGoh
3 Replies
Login or Register to Ask a Question