Листинг А.7. Функция main для измерения полосы пропускания очереди сообщений System V
//bench/bw_svmsg.c
1 #include "unpipc.h"
2 void reader(int, int, int);
3 void writer(int, int);
4 struct msgbuf *buf;
5 int totalnbytes, xfersize;
6 int
7 main(int argc, char **argv)
8 {
9 int i, nloop, contpipe[2], msqid;
10 pid_t childpid;
11 if (argc != 4)
12 err_quit("usage: bw_svmsg <#loops> <#mbytes> <#bytes/write>");
13 nloop = atoi(argv[1]);
14 totalnbytes = atoi(argv[2]) * 1024 * 1024;
15 xfersize = atoi(argv[3]);
16 buf = Valloc(xfersize);
17 Touch(buf, xfersize);
18 buf->mtype = 1;
19 Pipe(contpipe);
20 msqid = Msgget(IPC_PRIVATE, IPC_CREAT | SVMSG_MODE);
21 if ((childpid = Fork()) == 0) {
22 writer(contpipe[0], msqid); /* дочерний процесс */
23 exit(0);
24 }
25 Start_time();
26 for (i = 0; i < nloop; i++)
27 reader(contpipe[1], msqid, totalnbytes);
28 printf("bandwidth: %.3f MB/sec\n",
29 totalnbytes / Stop_time() * nloop);
30 kill(childpid, SIGTERM);
31 Msgctl(msqid, IPC_RMID, NULL);
32 exit(0);
33 }