-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_client_bonus.c
49 lines (44 loc) · 1.44 KB
/
main_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_client_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: HINATA <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/29 20:38:07 by HINATA #+# #+# */
/* Updated: 2021/09/29 20:38:07 by HINATA ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void write_error(char *s)
{
ft_putendl_fd(s, 1);
exit(0);
}
static void pid_handler(char *s_pid, char *s)
{
unsigned int pid;
int i;
int j;
pid = ft_atoi(s_pid);
j = 0;
while (s[j] != '\0')
{
i = 0;
while (i < 8)
{
if (kill(pid, (int []){SIGUSR1, SIGUSR2}[(s[j] >> i) & 1]) == -1)
write_error("\e[31mBAD PID( !_!)\e[m");
usleep(600);
i++;
}
j++;
}
}
int main(int argc, char **argv)
{
if (argc != 3)
write_error("\e[31mCOMMAND( !_!): ./client [server-pid] [message]\e[m");
pid_handler(argv[1], argv[2]);
return (0);
}