The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Signal Problem jacques83 High Level Programming 5 11-16-2006 09:30 PM
Signal question GCTEII Shell Programming and Scripting 1 04-14-2006 03:46 AM
I have a problem using signal SIGUSR2 khan_069 UNIX for Advanced & Expert Users 3 03-23-2006 03:35 PM
Signal Names laila63 High Level Programming 2 11-03-2004 09:27 AM
[Problem] raise a signal in FreeBSD Namely High Level Programming 1 11-08-2003 08:11 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Posts: 8
Exclamation problem with signal()

#include<signal.h>
void suicide();
main()
{
printf("use CTRL \\ for exiting \n");
//signal(SIGINT,SIG_DFL);
signal(SIGQUIT,suicide);
for (;;
}

void suicide()
{ printf("hello here you r in the suicide code ");
}




i was just starting with signals .. and tried this ,, but in the above i am calling suicide function in the signal function , its not working why ??
also the default behavior of the <ctrl \ > is being suppressed .

can you tell me why it is so ,,
and when i tried it passing SIG_DFL it worked ..
Reply With Quote
Forum Sponsor
  #2  
Old 11-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
put this in suicide

Code:
void suicide(int num)
{
    write(1,"suicide\n",8);
}
or put a \n in your printf, or use fflush(stdout);
Reply With Quote
  #3  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Posts: 8
ya a \n in the printf worked ,, Porter ,, can you tell me what was the problem ,, and now pressing CTRL \ first time is printing the message ,, but pressing it for the second time must quit it , i e the default action must be performed ,, but it is again printing the message ..???
Reply With Quote
  #4  
Old 11-15-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
if stdout is connected to a terminal then it does not fflush until a newline is written.

some operating systems require the signal handler to be reinstalled after calling, eg

Code:
void suicide(int num)
{ 
     ... set flags etc ....

     signal(num,suicide);
}
Reply With Quote
  #5  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Posts: 8
thanks porter .. i m using fedora core 7 ,,it seems that it doesn't need the signal handler to be called again.
Reply With Quote
  #6  
Old 11-15-2007
Registered User
 

Join Date: Sep 2007
Posts: 8
why the second printf in main is being executed after pressing CTRL \

#include<stdio.h>
#include<signal.h>
void suicide();
main()
{
printf("use CTRL \\ for exiting \n");
printf("iiiiiiiiiiiiiis");

//signal(SIGINT,SIG_DFL);
signal(SIGQUIT,suicide);
for (;;
}

/*void suicide()
{ printf("hello here you r in the suicide code\n ");
}*/

void suicide(int num)
{
printf("hii u r in suicide\n");
}


why the second printf in main is being executed after pressing CTRL \ . the iiiiiiiis is being printed only after i m pressing CTRL \ ,,

#include<stdio.h>
main()
{printf("hello u\n");
printf("hello how r yu again ");
}

while here both the print statements are being executed in one go .. ???
Reply With Quote
  #7  
Old 11-15-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
some operating systems require the signal handler to be reinstalled after calling, eg
I doubt whether it is operating system dependent.

It is dependent on the semantics of the signal used, whether older semantics is used or the newer semantics.

Once the function registered for signal handler is executed, the function has to be re-registered again to ensure that the function is executed when a signal of same type is received again

This is not needed with newer semantics, no need for re-registering it again and again.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0