-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
72 lines (65 loc) · 1.65 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
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mulken <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 11:12:08 by mulken #+# #+# */
/* Updated: 2023/01/30 11:23:45 by mulken ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
int ft_atoi(char *str)
{
int i;
int s;
int res;
i = 0;
s = 1;
res = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
s *= -1;
i++;
}
while (str[i] >= 48 && str[i] <= 57 && str[i])
{
res = (str[i] - 48) + (res * 10);
i++;
}
return (res * s);
}
void ft_send_signal(int pid, char *str)
{
int i;
unsigned char c;
while (*str)
{
i = 7;
c = *str++;
while (i >= 0)
{
if ((c >> i) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(200);
i--;
}
}
}
int main(int argc, char *argv[])
{
int pid;
if (argc != 3)
{
ft_printf("Error: wrong number of arguments\n");
return (0);
}
pid = ft_atoi(argv[1]);
ft_send_signal(pid, argv[2]);
}