-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
50 lines (44 loc) · 927 Bytes
/
client.c
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
#include "ipc.h"
void send_message(int pid, char *message)
{
int letter;
int i;
letter = 0;
while (message[letter])
{
i = -1;
while (++i < 8)
{
if (((unsigned char)(message[letter] >> (7 - i)) & 1) == 0)
kill(pid, SIGUSR1);
else if (((unsigned char)(message[letter] >> (7 - i)) & 1) == 1)
kill(pid, SIGUSR2);
usleep(50);
}
letter++;
}
i = 0;
while (i++ < 8)
{
kill(pid, SIGUSR1);
usleep(50);
}
}
int main(int argc, char **argv)
{
int pid;
char *message;
if (argc == 3)
{
pid = atoi(argv[1]);
message = argv[2];
printf("PID: %d\n", pid);
printf("Message: %s", message);
send_message(pid, message);
}
else
{
printf("Error: Merci d'entrer un PID et un Message");
}
return 0;
}