-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_client_bonus.c
60 lines (54 loc) · 1.46 KB
/
ft_client_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_client_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yopi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/08 04:20:08 by yopi #+# #+# */
/* Updated: 2022/01/14 03:29:28 by yopi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minitalk.h"
void ft_sendsig(char b_c, int pid)
{
int i;
i = 7;
while (i >= 0)
{
usleep(500);
if (b_c >> i & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
i--;
}
}
void handler2(int sig)
{
(void)sig;
write(1, "Signal Received", 15);
}
int main(int ac, char *av[])
{
int pid;
int i;
if (ac == 3 && ft_str_isnum(av[1]))
{
pid = ft_atoi(av[1]);
i = 0;
signal(SIGUSR2, &handler2);
while (av[2][i])
{
ft_sendsig(av[2][i], pid);
i++;
usleep(200);
}
}
else
{
write(1, "./client [server-pid] [message]\n", 33);
exit(0);
}
return (0);
}