[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

SIGPROF is masked by select() .



Hi,all
I am not sure if this list is suitable to issue such a question, but I am sure I am get help here.
There is a small program that both POSIX timer and select() call is used for timing.Either timer or select() works well when they run separately. But as both of them are used together, only the select() call works,the POSIX timer() is not work at all.
It's probablely that the timer signal SIGPROF is masked by select().
I read a bundle of manuals and found no answer, all said the select() could be interrupted by signals if not masked.

Below is the program,also,it is attached to this mail.
--------------------------------------------------------
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h> 
#include <sys/time.h>
#include <time.h>

/* ARGSUSED */
static void myhandler(int s) {
   char aster = '*';
   int errsave;
   errsave = errno;
   write(STDERR_FILENO, &aster, 1);
   errno = errsave;
}

static int setupinterrupt(void) {          /* set up myhandler for  SIGPROF */
   struct sigaction act;
   act.sa_handler = myhandler;
   act.sa_flags = 0;
   return (sigemptyset(&act.sa_mask) || sigaction(SIGPROF, &act, NULL));
}

static int setupitimer(void) {    /* set ITIMER_PROF for 2-second intervals */
   struct itimerval value;
   value.it_interval.tv_sec = 1;
   value.it_interval.tv_usec = 0;
   value.it_value = value.it_interval;
   return (setitimer(ITIMER_PROF, &value, NULL));
}
 
int main(void) {
   if (setupinterrupt()) {
      perror("Failed to set up handler for SIGPROF");
      return 1;
   }
   if (setupitimer() == -1) {
      perror("Failed to set up the ITIMER_PROF interval timer"); 
      return 1;
   } 

   time_t time_now;
   struct timeval tval;

   for ( ; ; )/* execute rest of main program here */
   {
	   tval.tv_sec=5;
	   tval.tv_usec=0;
	   select(0,NULL,NULL,NULL,&tval);
	   time(&time_now);
	   printf("now time is %s\n", ctime(&time_now)); 
   }
}

Attachment: periodicasterisk.c
Description: Binary data


Reply to: