LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   The terminal receives -1 after signal handler is invoked on timer expire. (https://www.linuxquestions.org/questions/linux-software-2/the-terminal-receives-1-after-signal-handler-is-invoked-on-timer-expire-754359/)

shylendra.kumar 09-11-2009 04:24 AM

The terminal receives -1 after signal handler is invoked on timer expire.
 
I have written a small program to set the elapse timer using posix calls timer_create & timer_settime. Associated the notification as SIGEV_SIGNAL.
The signal handler is invoked but after the completion of signal handler i could see that the terminal associated with the process gets -1.


Can any one tell what might be the problem and how do i solve this.
I am using this program to do a interacting test suite.

shylendra.kumar 09-11-2009 04:27 AM

Quote:

Originally Posted by shylendra.kumar (Post 3678427)
I have written a small program to set the elapse timer using posix calls timer_create & timer_settime. Associated the notification as SIGEV_SIGNAL.
The signal handler is invoked but after the completion of signal handler i could see that the terminal associated with the process gets -1.
Can any one tell what might be the problem and how do i solve this.
I am using this program to do a interacting test suite.

Actual piece of code
main()
{
int i = 0, rc;
struct sigevent sigVal;
struct sigaction sigAction;
timer_t timerid;
struct itimerspec timeout;
sigVal.sigev_signo = SIGALRM;
sigVal.sigev_notify = SIGEV_SIGNAL;
sigVal.sigev_value.sival_int = 100;
rc = timer_create(CLOCK_REALTIME, &sigVal, &timerid);
if(rc!=0)
{
printf("StyleGC --------- create failed \n");
return 0;
}
timeout.it_value.tv_sec = 2000/1000;
timeout.it_value.tv_nsec = 0;
timeout.it_interval.tv_sec = 1;
timeout.it_interval.tv_nsec = 0;
rc = timer_settime(timerid, CLOCK_REALTIME, &timeout, NULL);
if(rc!=0)
{
printf("StyleGC --------- SetTimer failed \n");
return 0;
}
sigAction.sa_sigaction = StyleSigHandler;
sigAction.sa_flags = SA_SIGINFO;
sigemptyset(&sigAction.sa_mask);
if(sigaction(SIGALRM, &sigAction, NULL) == -1)
{
printf("StyleGC --------- SigAction failed \n");
return 0;
}

while(1)
printf("StyleGC --- %c\n", getchar());
return 0;
}

Can any one please help me with this issue.
Thanks in advance.


All times are GMT -5. The time now is 09:57 PM.