-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
45 lines (40 loc) · 1.27 KB
/
server.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wboutzou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/14 18:37:22 by wboutzou #+# #+# */
/* Updated: 2022/04/21 13:07:22 by wboutzou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void sig_handler(int signum)
{
static int i = 7;
static int n = 0;
if (signum == SIGUSR1)
n |= 1;
else if (signum == SIGUSR2)
n |= 0;
i--;
if (i == -1)
{
write(1, &n, 1);
i = 7;
n = 0;
}
else
n = n << 1;
}
int main(void)
{
ft_putnbr(getpid());
write(1, "\n", 1);
signal(SIGUSR2, sig_handler);
signal(SIGUSR1, sig_handler);
while (1)
pause();
return (0);
}