void child(int msqid) { int i = 1; while (1) { msg_rcv(msqid, i); printf("Client: %d\n", i); fflush(stdout); msg_snd(msqid, i + 1); i += 2; } exit(0); }
void parent(int msqid) { int i = 1; for (i = 1; i < 32000; i += 2) { printf("Server: %d\n", i); fflush(stdout); msg_snd(msqid, i); msg_rcv(msqid, i + 1); sleep(1); } exit(0); }
void child(const char *mqname) { mqd_t mqdes = mq_open(mqname, O_RDWR | O_CREAT, 0666, 0); if (mqdes == -1) { perror("mq_open() failed"); exit(1); } int i=1; while (1) { msg_rcv(mqdes, i); printf("Client: %d\n", i); fflush(stdout); i++; } exit(0); }
void child(const char *mqname) { mqd_t mqdes = mq_open(mqname, O_RDWR | O_CREAT, 0666, 0); // Unfortunately, DMTCP doesn't yet support unlinking in child // while others use it: But this seems to work fine in the parent. // mq_unlink(mqname); /* parent and child will continue to use mqname */ if (mqdes == -1) { perror("mq_open() failed"); exit(1); } int i=1; while (1) { msg_rcv(mqdes, i); printf("Client: %d\n", i); fflush(stdout); i++; } exit(0); }