#include #include //ftok(). File-to-key? #include //msgget #include #include #include "queue.h" void report_and_exit(const char* msg) { perror(msg); exit(-1); } int main() { key_t key = ftok(PATHNAME, PROJECTID); if(key<0) report_and_exit("couldn't get key..."); printf("key is %i\n", key); //msgget() creates message queue //Returns System V message qid associated with value of key argument. int qid = msgget(key, 0666 | IPC_CREAT); printf("qid is %i\n", qid); //Ran into error here if(qid<0) report_and_exit("couldn't get queue id"); char* payloads[] = {"msg1","msg2","msg3","msg4","msg5","msg6"}; int types[] = {1,1,2,2,3,3}; int i; for( i = 0; i< MESSAGECOUNT ; i++) { //Type from queue.h queuedMessage msg; msg.type = types[i]; strcpy(msg.payload, payloads[i]); msgsnd(qid,&msg,MESSAGELENGTH + 1, IPC_NOWAIT); printf("%s sent as type %i\n", msg.payload, (int) msg.type); } return 0; }