aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--P2/include/utils.h2
-rw-r--r--P2/lib/utils.c13
2 files changed, 12 insertions, 3 deletions
diff --git a/P2/include/utils.h b/P2/include/utils.h
index 050a0e3..6fa4fa8 100644
--- a/P2/include/utils.h
+++ b/P2/include/utils.h
@@ -23,7 +23,9 @@ struct msgBuffer {
};
//Open Queue as a function because writing this once is probably better than four times.
//Hopefully it works properly.
+
int openQueue();
+void closeQueue();
// mapper side
int validChar(char c);
diff --git a/P2/lib/utils.c b/P2/lib/utils.c
index ede4931..8c27f4c 100644
--- a/P2/lib/utils.c
+++ b/P2/lib/utils.c
@@ -2,13 +2,20 @@
int openQueue() {
int id = msgget(ftok("4061 Project 2 SS", 'S'), 0666 | IPC_CREAT);
- if (id < 0)
- {
+ if (id < 0) {
perror("Cannot open queue.\n");
return -1;
- };
+ }
return id;
}
+void closeQueue() {
+ int msgid = msgget(ftok("4061 Project 2 SS", 'S'), 0666);
+ if (msgid < 0) {
+ perror("Cannot open queue. It may already exist.\n");
+ exit(-1);
+ }
+ msgctl(msgid, IPC_RMID, NULL);
+}
char *getChunkData(int mapperID) {
printf("GETTING CHUNK DATA\n");