-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
50 lines (45 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: asodor <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/22 09:55:11 by asodor #+# #+# */
/* Updated: 2024/05/12 16:39:38 by asodor ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void send_char(int pid, char c)
{
int shift;
int i;
i = 7;
while (i >= 0)
{
shift = 1 << (i);
if (c & shift)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(500);
i--;
}
}
int main(int ac, char **av)
{
pid_t pid;
int i;
if (ac != 3)
return (ft_putstr("Enter a valid ARGS"), 0);
pid = ft_mini_atoi(av[1]);
if (pid == 0)
return (ft_putstr("Invalid PID\n"), 0);
i = 0;
while (av[2][i])
{
send_char(pid, av[2][i]);
i++;
}
send_char(pid, '\0');
}