-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
55 lines (50 loc) · 1.51 KB
/
server.c
File metadata and controls
55 lines (50 loc) · 1.51 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hed-dyb <hed-dyb@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/20 15:42:07 by hed-dyb #+# #+# */
/* Updated: 2023/01/27 11:01:02 by hed-dyb ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void signals_handler(int signum, siginfo_t *info, void *extra)
{
static int pidcheck;
static unsigned char c;
static int i;
int signal;
(void)extra;
if (pidcheck != info->si_pid)
{
c = '\0';
i = 0;
pidcheck = info->si_pid;
}
signal = 0;
if (signum == SIGUSR1)
signal = 1;
c = c << 1;
c = c | signal;
i++;
if (i == 8)
{
write(1, &c, 1);
i = 0;
c = '\0';
}
}
int main(void)
{
struct sigaction cs;
ft_putnbr(getpid());
write(1, "\n", 1);
cs.sa_sigaction = &signals_handler;
cs.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &cs, NULL);
sigaction(SIGUSR2, &cs, NULL);
while (1)
pause();
}