-
Notifications
You must be signed in to change notification settings - Fork 0
/
removepostergado.cpp
67 lines (55 loc) · 1.45 KB
/
removepostergado.cpp
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
/**
* Gabriel Pereira Pinheiro - [email protected]
* Ismael Coelho Medeiros - [email protected]
* University of Brasilia - 2018
*/
#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <unistd.h>
using std::cout;
using std::endl;
#define MSGQ_REM_KEY 0x1224
struct removeMessage
{
long pid;
int id_job;
};
typedef struct removeMessage RemoveMessage;
/**
* Processes the arugments received from terminal.
*/
bool tryProcessArguments(int nArgs, char *args[], int* id_job);
int main(int argc, char *argv[])
{
int id_job;
if (!tryProcessArguments(argc, argv, &id_job)) {
cout << "Something went wrong!! This program will be closed." << endl;
exit(1);
}
int mqid;
if ((mqid = msgget(MSGQ_REM_KEY, IPC_CREAT|0x1B6)) < 0) {
cout << "Error on message queue creation!! This program will be closed." << endl;
exit(1);
}
RemoveMessage message;
message.pid = getpid();
message.id_job = id_job;
if ((msgsnd(mqid, &message, sizeof(message) - sizeof(long), 0)) < 0) {
cout << "Error while sending the message." << endl;
exit(1);
}
cout << "Removal request sent successfully to Job ID: " << id_job << endl;
exit(0);
}
bool tryProcessArguments(int nArgs, char *args[], int* id_job)
{
if (nArgs != 2)
{
cout << "ARGUMENT ERROR: Missing arguments" << endl;
return false;
}
*id_job = atoi(args[1]);
return true;
}