Top Forums Programming why multiple SIGINT raises when i hit C-c Post 302356719 by Sedighzadeh on Sunday 27th of September 2009 05:20:13 AM
Old 09-27-2009
why multiple SIGINT raises when i hit C-c

hi,

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()
{

signal(SIGINT,CleanExit);

sigset_t set;
sigset_t old_set;

sigemptyset(&set);
sigemptyset(&old_set);

sigaddset (&set, SIGINT);

// run other threads ...

while( 1 )
{
if ( setjmp (main_loop) )
{
pthread_sigmask(SIG_BLOCK,&set,&old_set);
/// Clean up and shut down threads
pthread_sigmask(SIG_UNBLOCK,&set,&old_set);
break;
}
}

printf("\nbye!\n");
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,
Sedighzade
 

7 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

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. 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

6. 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

7. 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 http://192.168.21.20:8080/PPUPS/international?NUmber=917875446856... (3 Replies)
Discussion started by: mukulverma2408
3 Replies
SIGSETMASK(3)						   BSD Library Functions Manual 					     SIGSETMASK(3)

NAME
sigsetmask -- set current signal mask LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <signal.h> int sigsetmask(int mask); sigmask(signum); DESCRIPTION
This interface is made obsolete by: sigprocmask(2). sigsetmask() sets the current signal mask Signals are blocked from delivery if the corresponding bit in mask is a 1; the macro sigmask() is provided to construct the mask for a given signum. The system quietly disallows SIGKILL or SIGSTOP to be blocked. RETURN VALUES
The previous set of masked signals is returned. EXAMPLES
The following example using sigsetmask(): int omask; omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP)); ... sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP))); Could be converted literally to: sigset_t set, oset; sigemptyset(&set); sigaddset(&set, SIGINT); sigaddset(&set, SIGHUP); sigprocmask(SIG_BLOCK, &set, &oset); ... sigdelset(&oset, SIGINT); sigdelset(&oset, SIGHUP); sigprocmask(SIG_SETMASK, &oset, NULL); Another, clearer, alternative is: sigset_t set; sigemptyset(&set); sigaddset(&set, SIGINT); sigaddset(&set, SIGHUP); sigprocmask(SIG_BLOCK, &set, NULL); ... sigprocmask(SIG_UNBLOCK, &set, NULL); To completely clear the signal mask using sigsetmask() one can do: (void) sigsetmask(0); Which can be expressed via sigprocmask(2) as: sigset_t eset; sigemptyset(&eset); (void) sigprocmask(SIG_SETMASK, &eset, NULL); SEE ALSO
kill(2), sigaction(2), sigprocmask(2), sigsuspend(2), sigblock(3), sigsetops(3), sigvec(3) HISTORY
The sigsetmask() function call appeared in 4.2BSD and has been deprecated. BSD
August 10, 2002 BSD

Featured Tech Videos

All times are GMT -4. The time now is 06:26 AM.
Unix & Linux Forums Content Copyright 1993-2021. All Rights Reserved.
Privacy Policy