Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.system > #393

Re: Linux c alarm signal cannot receive

From Josef Moellers <josef.moellers@ts.fujitsu.com>
Newsgroups comp.os.linux.development.system
Subject Re: Linux c alarm signal cannot receive
Date 2012-02-09 13:54 +0100
Organization Fujitsu Technology Solutions
Message-ID <jh0fld$l3n$1@nntp.ts.fujitsu.com> (permalink)
References <ead58a70-4307-4056-bf69-1a7d67c35eea@qv4g2000pbc.googlegroups.com> <87ehu6a8gv.fsf@sapphire.mobileactivedefense.com>

Show all headers | View raw


Am 9.2.2012 schrub Rainer Weikusat:

> knightmare <knightmare1980@gmail.com> writes:
>> no "get signal" printed....why
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <signal.h>
>> #include <time.h>
>> #include <strings.h>
>> #include <unistd.h>
>>
>> void alarmhandler(int signum){
>>         printf("get signal %d\n",signum);
>> }
>> int main() {
>>   struct sigaction sa;
>>   bzero(&sa, sizeof sa);
>>   sa.sa_handler = alarmhandler;
>>   sigaction(SIGINT, &sa, 0);
>>   if(sigaction(SIGALRM, &sa, 0)==0){
>>     printf("success\n");
>>   }
>>   alarm(2);
>>   for(;;);
>> }
> 
> Works for me.

Same here:
josef@bounty:~/Test$ ./sig
success
get signal 14

One observation:
The program will not terminate when the signal was received AND it
outputs to stdout.
Now, when connected to a terminal, stdout should not be buffered, but
sh*t happenz ...

To the OP:
Try replacing the printf("get signal %d\n",signum); by an
fprintf(stderr, ...) OR add a "fflush(stdout);" to the alarmhandler.

Maybe the output is just kept under house arrest and is not allowed to
play outside ;-)

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html

Back to comp.os.linux.development.system | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Linux c alarm signal cannot receive knightmare <knightmare1980@gmail.com> - 2012-02-07 08:25 -0800
  Re: Linux c alarm signal cannot receive Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-02-07 16:56 +0000
    Re: Linux c alarm signal cannot receive Josef Moellers <josef.moellers@ts.fujitsu.com> - 2012-02-09 13:54 +0100
  Re: Linux c alarm signal cannot receive David Schwartz <davids@webmaster.com> - 2012-02-19 18:31 -0800

csiph-web