+
+/**
+ * Shared memory variables
+ */
+/**
+ * Memory key for processes. Must be same between all processes to properly
+ * communicate.
+ */
+key_t shmkey = 18912;
+/**
+ * Id of the shared memory
+ */
+int shmid;
+
+/**
+ * Structure holding array of process IDs.
+ * Message is shared by processes. Contains array of process IDs
+ */
+struct message {
+ pid_t pids[3];
+};
+
+struct message * processes = NULL;
+
+/**
+ * Message Queue variables
+ */
+
+/**
+ * Unique key of message queue.
+ */
+key_t qkey = 12356;
+
+/**
+ * Queue descriptor.
+ */
+int qid;
+
+/**
+ * Structure holding queue message data.
+ * Parameter mtype describes process to whom message is sent.
+ * Parameter signo is a signal to raise after getting message.
+ */
+struct queue_message {
+ long mtype;
+ int signo[1];
+};
+
+void notify_other_processes(int signo) {
+ int i = 0;
+ struct queue_message msg;
+ msg.signo[0] = signo;
+
+ for (; i < 3; i++) {
+ pid_t pid = processes->pids[i];
+ // Bleh
+ if (i != 2 && pid != 0) {
+ msg.mtype = i+1;
+ fprintf(stderr, "[%s] Sending message of type (%d) with value %d\n", "process3", msg.mtype, msg.signo[0]);
+ msgsnd(qid, &msg, sizeof(int), 0);
+ fprintf(stderr, "[%s] Sending signal %s (%d) to PID: %d\n", "process3", strsignal(SIGUSR1), SIGUSR1, pid);
+ kill(pid, SIGUSR1);
+ }
+ }
+}
+