-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_bonus.c
63 lines (57 loc) · 1.48 KB
/
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
61
62
63
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: inkahar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/27 13:48:18 by inkahar #+# #+# */
/* Updated: 2024/01/29 20:05:51 by inkahar ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void sighandler(int sig)
{
(void)sig;
write(1, "Signal received\n", 16);
exit(0);
}
void client(int pid, char c)
{
int i;
i = 8;
while (i > 0)
{
i--;
if ((c >> i) & 1)
kill(pid, SIGUSR1);
else
kill(pid, SIGUSR2);
usleep(200);
}
}
int main(int argc, char **argv)
{
int i;
int pid;
i = 0;
if (argc != 3)
{
write(1, "Wrong format, try ./client\n", 27);
return (1);
}
if (argc == 3)
{
pid = ft_atoi(argv[1]);
while (argv[2][i])
{
client(pid, argv[2][i]);
i++;
}
client(pid, '\0');
signal(SIGUSR1, sighandler);
while (1)
pause();
}
return (0);
}