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

SIGPROF is masked by select() .

I am not sure it is suitable to issue such a question here.
I wrote a small program that both POSIX timer and select() call are used for timing. 
Either timer or select() works well when they are used 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.

Here is the program.
#include <errno.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h> 
#include <sys/time.h>
#include <time.h>

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 */
	   printf("now time is %s\n", ctime(&time_now)); 

Reply to: