Is SIGALRM getting masked ???

A

apoorva.groups

I am using setitimer function to timeout of the processing that I
doing.

I wrote a small program and it seems to be working...
It works with the cgi for values less than 1024 but for values more
that that it does not work.


I tried to use alarm but again it is not timing out. I am not sure
whether the SIGALRM is getting masked. If that is the case How to
make
sure that SIGALRM is not masked.


main()
{
long int Timer_Sec = 1800;
struct itimerval rttimer;

signal(SIGALRM,handler);
rttimer.it_value.tv_sec = Timer_Sec;
rttimer.it_value.tv_usec = 0;
rttimer.it_interval.tv_sec = 10;
rttimer.it_interval.tv_usec = 0;

system("date");

setitimer (ITIMER_REAL, &rttimer, NULL);

// alarm(Timer_Sec+120);

for(;;);

}

void handler(int sig)
{
static int i = 0;
i++;

system("date");
printf("signal handler for %d\n",sig);
exit(1);

}
 
D

David Thompson

I am using setitimer function to timeout of the processing that I
doing.

I wrote a small program and it seems to be working...
It works with the cgi for values less than 1024 but for values more
that that it does not work.


I tried to use alarm but again it is not timing out. I am not sure
whether the SIGALRM is getting masked. If that is the case How to
make
sure that SIGALRM is not masked.
Neither setitimer() nor alarm()/SIGALARM is included in Standard
(portable) C and hence they are offtopic here. comp.unix.programmer is
the most obvious place they are ontopic. I assume by 'cgi' you mean
the webserving environment; if that is actually relevant I'm not sure
where that is ontopic. But a few points:

You must have #include'd several relevant headers for your code to
compile at all, and perhaps more for it to work correctly. You may be
thinking that they aren't relevant to your question, but such thinking
is sometimes wrong; better to be clear even if a bit longer.

Aside: This is legal prior to C99, but even so it is better to specify
int main (void)
{
long int Timer_Sec = 1800;
struct itimerval rttimer;
1800 seconds is 30 minutes (and 1920 is 32 minutes). That's a pretty
long time for a person to wait. Or even(?) a webserver.
signal(SIGALRM,handler);
rttimer.it_value.tv_sec = Timer_Sec;
rttimer.it_value.tv_usec = 0;
rttimer.it_interval.tv_sec = 10;
rttimer.it_interval.tv_usec = 0;

system("date");

setitimer (ITIMER_REAL, &rttimer, NULL);

// alarm(Timer_Sec+120);
(doubleslash comments are legal _only_ in C99, so formally this
conflicts with the implicit-int main. Both are legal in GNU C though.)
for(;;);

}

void handler(int sig)
{
static int i = 0;
i++;

system("date");
printf("signal handler for %d\n",sig);

The list of things you can safely do in a Standard C signal handler
routine is very short; for a POSIX/Unix one is is somewhat longer, but
still does not include system() and printf(). Although for your _very_
simplified example, they are quite likely to work.
exit(1);

}
- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top