-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
60 lines (53 loc) · 1.55 KB
/
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
51
52
53
54
55
56
57
58
59
60
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hameur <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/07 15:56:23 by hameur #+# #+# */
/* Updated: 2022/04/14 12:57:35 by hameur ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include "libft/libft.h"
//SIGUSR1 = 0
//SIGUSR2 = 1
void read_to_binary(char c, int pid)
{
int i;
int error;
i = 8;
while (i-- > 0)
{
if ((c >> i) & 1)
error = kill(pid, SIGUSR2);
else
error = kill(pid, SIGUSR1);
usleep(800);
if (error == -1)
return (write(1, "Error sending signal\n", 22), exit(0));
}
}
void usage(void)
{
write(1, "./client pid “msg“\n", 18);
exit(0);
}
int main(int ac, char **av)
{
int pid;
int i;
char *msg;
i = -1;
if (ac != 3)
usage();
msg = av[2];
pid = ft_atoi(av[1]);
while (msg[++i])
read_to_binary(msg[i], pid);
read_to_binary(msg[i], pid);
return (0);
}