Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

signal doubt

Status
Not open for further replies.

nnair

Technical User
May 22, 2002
4
IN
Hi,
Given below is a sample pgm which I read in a book. Acc, to the book, this pgm should call function ‘abc’ the 1st time Ctrl^C is pressed & when Ctrl^C is pressed 2nd time it should terminate the pgm. But when I tried executing the same pgm in Linux, every time, Ctrl^C was pressed, the pgm called ‘abc’ function & went in infinite loop.
Could anyone tell me why did this happen & what is the default beavior?

#include<signal.h>

void abc();
main()
{
printf(“Press Key\n”);
signal(SIGINT,abc);
for(;;);
}

void abc()
{
printf(“U have pressed the key”):
}

Thanx,
N
 
Don't know a lot about signal handlers -- but don't you have to uninstall the handler as your first action *in* the handler? Mike

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
I think it depends on Unix implementation. In LINUX the handler keeps installed until you uninstall it by calling, for example, the sigignore(SIGINT) function, but in another Unix systems ( i have tried in HP-UX ) every time the signal is caught it is unistalled automatically and you must call again the signal function to maintain the handler active.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top