Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <errno.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <sys/msg.h>
- #include <signal.h>
- void
- gottimeout(int signal) {
- }
- int
- main(void) {
- int timeout = 5;
- int msgqid;
- char buf[100];
- msgqid = msgget(1234, IPC_CREAT);
- signal(SIGALRM, gottimeout);
- while(1) {
- alarm(timeout);
- if(msgrcv(msgqid, buf, sizeof(buf), 0, 0) == -1) {
- if(errno == EINTR) {
- printf("eintr!\n");
- } else {
- perror("msgrcv");
- return 1;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment