-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathafter_use_checker.cpp
More file actions
77 lines (66 loc) · 1.55 KB
/
after_use_checker.cpp
File metadata and controls
77 lines (66 loc) · 1.55 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <iostream>
#define PERM 0666
const char kLogFile[] = "transit";
bool SemaphoreCheck(key_t key, short num_of_sems) {
int descriptor = semget(key, num_of_sems, PERM);
bool result = descriptor < 0;
if (!result) {
semctl(descriptor, num_of_sems, IPC_RMID, NULL);
}
return result;
}
bool MsgQueueCheck(key_t key) {
int descriptor = msgget(key, PERM);
bool result = descriptor < 0;
if (!result) {
msgctl(descriptor, IPC_RMID, NULL);
}
return result;
}
int main() {
std::cout << "Mine msg: ";
if (MsgQueueCheck(ftok(kLogFile, 1))) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "Factory msg: ";
if (MsgQueueCheck(ftok(kLogFile, 2))) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "Mine sem: ";
if (SemaphoreCheck(ftok(kLogFile, 3), 1)) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "Factory sem: ";
if (SemaphoreCheck(ftok(kLogFile, 4), 1)) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "Traffic Controller sem: ";
if (SemaphoreCheck(ftok(kLogFile, 5), 1)) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "End sem: ";
if (SemaphoreCheck(ftok(kLogFile, 6), 1)) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
std::cout << "Num of users sem: ";
if (SemaphoreCheck(ftok(kLogFile, 7), 2)) {
std::cout << "OK\n";
} else {
std::cout << "error\n";
}
}