Ich habe dieses Problem mit Alarmsignal gelöst.
Überprüfen Sie bitte das folgende Programm, wenn es hilft:
int msg_recv(int id, MSG_DATA *msgptr)
{
int n;
**alarm(2);** //After 2 second msg_recv interrupt and return errno "Interrupted system call"
n = msgrcv(id, (MSG_DATA *) msgptr, sizeof(MSG_DATA) , 0, 0);
perror("Return from msgrcv");
printf ("N = %d\n %d %s\n\n",n,errno,strerror(errno));
if (n < 0) //goto LOOP; // This forces the interrupted msgrcv to repeat
return(n);
}
void sigalrm_handler()
{
printf("Alarm signal delivered !\n");
return;
}
int main();
int main()
{
//signal (SIGALRM, times_up); /* go to the times_up function */
/* when the alarm goes off. */
**signal(SIGALRM, sigalrm_handler);**
int msqid; /* return value from msgget() */
MSG_DATA msg_data;
msqid = 0;
printf("Ready to receive ... \n");
**msg_recv(msqid, &msg_data);**
printf("read message \n");
return 0;
}
möglich Duplikat http://stackoverflow.com/questions/4110198/system- v-Nachrichtenwarteschlange-zeitgesteuert empfangen – jschmier