-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.c
68 lines (61 loc) · 1.61 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: zbabahmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/10 16:08:17 by zbabahmi #+# #+# */
/* Updated: 2023/03/03 17:57:22 by zbabahmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void convert_dec(char *str)
{
int i;
char c;
i = 0;
while (i < 8)
{
c = c * 2 + str[i] - 48;
i++;
}
ft_putchar(c);
}
void handler(int signal, siginfo_t *info, void *utp)
{
static char str[8];
static int i;
static int remember;
int a;
(void)utp;
a = info->si_pid;
if (a != remember)
{
i = 0;
remember = a;
}
if (signal == SIGUSR1)
str[i++] = '0';
if (signal == SIGUSR2)
str[i++] = '1';
if (i == 8)
{
convert_dec(str);
i = 0;
}
}
int main(void)
{
int pid;
struct sigaction creminal;
creminal.sa_sigaction = handler;
creminal.sa_flags = 0;
pid = getpid();
ft_putnbr(pid);
sigaction(SIGUSR1, &creminal, NULL);
sigaction(SIGUSR2, &creminal, NULL);
write(1, "\n", 1);
while (1)
;
}