Once the alarm(5)
or what ever seconds is started and running, after some time in the program if some actions happens I need to reset the alarm again to alarm(5)
. How can I achieve this?
Any alarm reset()
available?
int flag=0;
void alarmhand(int signal)
{
flag=1;
// printf("\n time out");
}
void main()
{
signal(SIGALRM,alarmhand);
alarm (5);
while(1)
{
event_status();
if(flag==1)
break;
}
}
void event_status()
{
int reset;
printf("reset 1=y/2=n :");
scanf("%d",&reset);
if(reset==1)
{
// alarm.reset(5);
// HOW DO I RESET THE ALARM AGAIN TO 5 HERE ??
}
}
You can just set the new alarm and the old one will be cancelled:
alarm (5);
From the Linux alarm
man page, slightly paraphrased):
alarm()
arranges for aSIGALRM
signal to be delivered to the calling process in a specified number of seconds.If the specified number of seconds is zero, no new alarm is scheduled.
In any event any previously set alarm is canceled.
As noted, any current alarm is cancelled by a call to alarm()
before anything else. A new one won't be created if the argument to alarm()
is zero.
So alarm(0)
will cancel any currently active alarm, while alarm(5)
will either create a new alarm of, or reset a currently active alarm to, 5 seconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With