From dde37c31a72f4773e95faf8223ef450440bdb62c Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Sun, 17 Jan 2021 12:57:21 -0600 Subject: get rid of that trash --- csci4061/102620_breakout/msg_queue_template.c | 108 -------------------------- 1 file changed, 108 deletions(-) delete mode 100644 csci4061/102620_breakout/msg_queue_template.c (limited to 'csci4061/102620_breakout') diff --git a/csci4061/102620_breakout/msg_queue_template.c b/csci4061/102620_breakout/msg_queue_template.c deleted file mode 100644 index af026f3..0000000 --- a/csci4061/102620_breakout/msg_queue_template.c +++ /dev/null @@ -1,108 +0,0 @@ -/* -* Recitation Section Number: 02 -* Breakout Number: 05 -* Graden Hill (hill1582) -* Gustav Baumgart (baumg260) -* Matt Strapp (strap012) -* Skylan Recnana (recan001) -*/ - -#include -#include -#include -#include -#include -#include -#include - -#define PERM 0666 -#define MSGSIZE 100 -#define NCHILD 3 - -// structure for message queue -typedef struct msg_buffer { - long mtype; - char mtext[MSGSIZE]; -} message; - -int main(void) { - key_t key; - int msgid; - pid_t pid1, pid2; - message msg; - - // generate unique key - key = ftok("recitation", 4061); - - // creates a message queue - msgid = msgget(key, PERM | IPC_CREAT); - - - // sender child process - pid1 = fork(); - if (pid1 == 0) { - for (int i = 0; i < NCHILD; i++) { - msg.mtype = 111; - memset(msg.mtext, '\0', MSGSIZE); - sprintf(msg.mtext, "Hello child %d", i); - // send message to other child processes - msgsnd(msgid, &msg, MSGSIZE, 0); - - - // display the message - printf("[%d] Data sent is : %s \n", i, msg.mtext); - } - - for (int i = 0; i < NCHILD; i++) { - msg.mtype = 222; - memset(msg.mtext, '\0', MSGSIZE); - sprintf(msg.mtext, "Message %d", i); - // send message to other child processes - msgsnd(msgid, &msg, MSGSIZE, 0); - - // display the message - printf("[%d] Data sent is : %s \n", i, msg.mtext); - } - - for (int i = 0; i < NCHILD; i++) { - msg.mtype = 333; - memset(msg.mtext, '\0', MSGSIZE); - sprintf(msg.mtext, "Bye %d", i); - // send message to other child processes - msgsnd(msgid, &msg, MSGSIZE, 0); - - // display the message - printf("[%d] Data sent is : %s \n", i, msg.mtext); - } - - exit(0); - } else if (pid1 < 0) { - printf("fork1 error\n"); - return -1; - } - - // receiver child processes - for (int j = 0; j < NCHILD; j++) { - if ((pid2 = fork()) == 0) { - // receive message - msgrcv(msgid, &msg, MSGSIZE, 222, 0); - - - // display the message - printf("[%d] Data received is : %s \n", j, msg.mtext); - - exit(0); - } else if (pid2 < 0) { - printf("fork2 error\n"); - return -1; - } - } - - while (wait(NULL) > 0); - - // to destroy the message queue - msgctl(msgid, IPC_RMID, NULL); - - - return 0; -} \ No newline at end of file -- cgit v1.2.3