/*******************************************************************************/ /* jg151.cc -- Generating message queues * * Message queue generation * John Gray, Inrerprocess Communications in UNIX, P.151 */ #include #include #include #include #include #include #include #define MAX 5 int main(void){ FILE *fin; char buffer[PIPE_BUF], u_char = 'A'; int i, n, mid[MAX]; key_t key; for(i=0; i < MAX; ++i, ++u_char){ //key = ftok(".", u_char); key = getuid()+i; if((mid[i] = msgget(key, IPC_CREAT | 0660)) == -1){ perror("Queue creat"); exit(1); } } fin = popen("ipcs", "r"); /* run the ipcs command*/ while((n=read(fileno(fin), buffer, PIPE_BUF)) > 0) write(fileno(stdout), buffer, n); /* display ipcs output */ pclose(fin); for(i=0; i