Guest User

Untitled

a guest
Mar 12th, 2014
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/ipc.h>
  6. #include <sys/msg.h>
  7. #include <signal.h>
  8.  
  9. void
  10. gottimeout(int signal) {
  11. }
  12.  
  13. int
  14. main(void) {
  15.     int timeout = 5;
  16.     int msgqid;
  17.     char buf[100];
  18.  
  19.     msgqid = msgget(1234, IPC_CREAT);
  20.     signal(SIGALRM, gottimeout);
  21.  
  22.     while(1) {
  23.     alarm(timeout);
  24.         if(msgrcv(msgqid, buf, sizeof(buf), 0, 0) == -1) {
  25.         if(errno == EINTR) {
  26.         printf("eintr!\n");
  27.         } else {
  28.         perror("msgrcv");
  29.         return 1;
  30.         }
  31.     }
  32.     }
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment