-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_server_bonus.c
51 lines (45 loc) · 1.48 KB
/
main_server_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_server_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: HINATA <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/09/29 20:38:19 by HINATA #+# #+# */
/* Updated: 2021/09/29 20:40:32 by HINATA ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void pid_print(void)
{
ft_putstr_fd("\e[32mSERVER PID_(:3 <)_ : \e[m", 1);
ft_putnbr_fd(getpid(), 1);
}
static void sig_handler(int a)
{
static unsigned char ch;
static unsigned int bit_n;
if (!(a == SIGUSR1 || a == SIGUSR2))
write(1, "\e[31mBAD SIGNAL( !_!)\e[m", 16);
if (a == SIGUSR2)
ch |= (1 << bit_n);
if (bit_n == 7)
{
ft_putchar_fd(ch, 1);
bit_n = 0;
ch = 0;
}
else
bit_n++;
}
int main(void)
{
struct sigaction sig;
pid_print();
sig.sa_handler = &sig_handler;
sigaction(SIGUSR1, &sig, NULL);
sigaction(SIGUSR2, &sig, NULL);
while (1)
pause();
return (0);
}