/* Using the message queue IPC */ /* Sending process */ /* Initial variant */ #include #include #include #include #include #include #define MSQSIZ 1024 struct msgbf { long mtype; char mtext [MSQSIZ]; }; int main (int argc, char * argv[]) {int msid, v; int i; struct msgbf mess; if (argc != 4) {printf ("Usage: \n"); exit (1);} /* Creating or get message queue */ msid = msgget ((key_t) atoi (argv[1]), IPC_CREAT | 0666); if (msid == -1) {printf("Cannot get message queue\n"); exit (1);} /* Prepare a message from command line parameters */ mess.mtype = atoi (argv[2]); strcpy (mess.mtext, argv[3]); printf("Wait... Sender is working...\n"); /* Write the message into the queue */ v = msgsnd(msid, (struct msgbuf *)&mess, strlen(argv[3]) + 1, 0); if (v < 0) printf("ERROR writing to message queue\n"); printf("Sender terminated\n"); exit(0); }