-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanup.c
More file actions
53 lines (45 loc) · 1.34 KB
/
cleanup.c
File metadata and controls
53 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/shm.h>
struct Message {
long mType;
int sqno;
int opno;
char filename[100];
};
int main() {
key_t msgQueueKey = ftok("/myMsgQueue", 'A'); // Unique key for the message queue
int msqid = msgget(msgQueueKey,0666);
if (msqid == -1) {
perror("Error creating message queue");
exit(EXIT_FAILURE);
}
while (1) {
char choice;
printf("Want to terminate the application? Press Y (Yes) or N (No)\n");
scanf(" %c", &choice);
if (choice == 'Y' || choice == 'y') {
struct Message msg;
msg.mType = 1;
msg.opno = 5; //used to clarify to the server that its cleanup and not client
// Inform load balancer to terminate
if (msgsnd(msqid, &msg, sizeof(struct Message), 0) == -1) {
perror("msgsnd");
exit(EXIT_FAILURE);
}
printf("Cleanup process terminated.\n");
exit(EXIT_SUCCESS);
}
else if (choice == 'N' || choice == 'n') {
// Continue running as usual
}
else {
printf("Invalid choice. Please enter Y or N.\n");
}
}
return 0;
}