int main(int argc, char **argv) { int msqid; struct msqid_ds info; struct msgbuf buf; msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT); buf.mtype = 1; buf.mtext[0] = 1; Msgsnd(msqid, &buf, 1, 0); Msgctl(msqid, IPC_STAT, &info); printf("read-write: %03o, cbytes = %lu, qnum = %lu, qbytes = %lu\n", info.msg_perm.mode & 0777, (unsigned long int) info.msg_cbytes, (unsigned long int ) info.msg_qnum, (unsigned long int) info.msg_qbytes); int ret = system("ipcs -q"); if( ret == -1){ perror("system\n"); printf("Error in system call\n"); } Msgctl(msqid, IPC_RMID, NULL); exit(0); }
int main(int argc, char **argv) { int i, nloop, contpipe[2], msqid; pid_t childpid; if (argc != 4) err_quit("usage: bw_svmsg <#loops> <#mbytes> <#bytes/write>"); nloop = atoi(argv[1]); totalnbytes = atoi(argv[2]) * 1024 * 1024; xfersize = atoi(argv[3]); buf = Valloc(xfersize); Touch(buf, xfersize); buf->mtype = 1; Pipe(contpipe); msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE); if ( (childpid = Fork()) == 0) { writer(contpipe[0], msqid); /* child */ exit(0); } Start_time(); for (i = 0; i < nloop; i++) reader(contpipe[1], msqid, totalnbytes); printf("bandwidth: %.3f MB/sec\n", totalnbytes / Stop_time() * nloop); kill(childpid, SIGTERM); Msgctl(msqid, IPC_RMID, NULL); exit(0); }
int main(int argc, char **argv) { int readid, writeid; /* 4assumes server has created the queues */ writeid = Msgget(MQ_KEY1, 0); readid = Msgget(MQ_KEY2, 0); client(readid, writeid); /* 4now we can delete the queues */ Msgctl(readid, IPC_RMID, NULL); Msgctl(writeid, IPC_RMID, NULL); exit(0); }
int main(int argc, char **argv) { int msqid; struct msqid_ds info; struct msgbuf buf; msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE); buf.mtype = 1; buf.mtext[0] = 1; Msgsnd(msqid, &buf, 1, 0); Msgctl(msqid, IPC_STAT, &info); printf("read-write: %03o, cbytes = %lu, qnum = %lu, qbytes = %lu\n", info.msg_perm.mode & 0777, (ulong) info.msg_cbytes, (ulong) info.msg_qnum, (ulong) info.msg_qbytes); system("ipcs -q"); Msgctl(msqid, IPC_RMID, NULL); exit(0); }
int main(int argc, char **argv) { int mqid; if (argc != 2) err_quit("Usage: rmid <pathname>"); mqid = Msgget(Ftok(argv[1], 0), 0); Msgctl(mqid, IPC_RMID, NULL); exit(0); }
int main(int argc, char **argv) { int i, msqid; for (i = 0; i < 10; i++) { msqid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT); printf("msqid = %d\n", msqid); Msgctl(msqid, IPC_RMID, NULL); } exit(0); }
int main(int argc, char **argv) { int readid, writeid; /* server must create its well-known queue */ writeid = Msgget(MQ_KEY1, 0); /* we create our own private queue, and in client() we tranport our queue id to server */ readid = Msgget(IPC_PRIVATE, SVMSG_MODE | IPC_CREAT); client(readid, writeid); /* work done , and delete our private queue */ Msgctl(readid, IPC_RMID, NULL); exit(0); }