/* a sample program that prints the first 10 identifier values
 returned by msgget, and then removes the message queue. */
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define KEY ((key_t) 98765L)
#define PERMS 0666

int main() {
    int i, msqid;
    
    for(i = 0; i < 10; i++) {
      if((msqid = msgget(KEY,PERMS|IPC_CREAT)) < 0)
         fprintf(stderr,"can't create message queue");
      printf("msqid = %d\n",msqid);
      if(msgctl(msqid,IPC_RMID, (struct msqid_ds *) 0 ) < 0)
         fprintf(stderr,"can't remove message queue");
    } 
}
