-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
71 lines (64 loc) · 1.62 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
61
62
63
64
65
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atangil <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/17 15:50:04 by atangil #+# #+# */
/* Updated: 2023/09/18 12:08:27 by atangil ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
#include <unistd.h>
void kill_ch(int pid, char c)
{
int i;
i = 7;
while (i >= 0)
{
if (((c >> i) & 1) == 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(100);
i--;
}
}
int ft_atoi(const char *str)
{
int sign;
int res;
int i;
res = 0;
sign = 1;
i = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-')
sign *= -1;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] <= '9' && str[i] >= '0')
{
res = ((str[i] - 48) + (res * 10));
i++;
}
return (res * sign);
}
int main(int argc, char **argv)
{
int i;
i = 0;
if (argc != 3)
{
write(1, "Error\n", 6);
return (0);
}
while (argv[2][i])
{
kill_ch(ft_atoi(argv[1]), argv[2][i]);
i++;
}
return (0);
}