-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.c
59 lines (53 loc) · 1.48 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kael-ala <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/19 23:46:46 by kael-ala #+# #+# */
/* Updated: 2024/03/03 19:47:40 by kael-ala ### ########.fr */
/* */
/* ************************************************************************** */
#include "./include/minitalk.h"
#include "./include/ft_printf.h"
void ft_kill(pid_t pid, int sig)
{
if (kill(pid, sig) < 0)
{
ft_printf("Failed to send signal to %d\n", pid);
exit(EXIT_FAILURE);
}
}
void send_sig(pid_t pid, char *str)
{
int i;
while (*str)
{
i = 0;
while (i <= 7)
{
if ((*str >> i) & 1)
ft_kill(pid, SIGUSR1);
else
ft_kill(pid, SIGUSR2);
i++;
usleep(900);
}
str++;
}
}
int main(int ac, char **av)
{
pid_t pidd;
if (ac == 3)
{
pidd = ft_atoi(av[1]);
send_sig(pidd, av[2]);
}
else
{
ft_printf("Opps, Something went wrong\n");
exit(EXIT_FAILURE);
}
}