-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
57 lines (51 loc) · 1.71 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: igenial <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/27 17:58:26 by igenial #+# #+# */
/* Updated: 2023/10/10 00:54:14 by igenial ### ########.fr */
/* */
/* ************************************************************************** */
#include "mini_talk.h"
void handler(int signum, siginfo_t *info, void *context);
int main(void)
{
int pid;
struct sigaction s_sig;
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGUSR1);
sigaddset(&sigset, SIGUSR2);
s_sig.sa_handler = NULL;
s_sig.sa_flags = SA_SIGINFO;
s_sig.sa_mask = sigset;
s_sig.sa_sigaction = handler;
sigaction(SIGUSR1, &s_sig, NULL);
sigaction(SIGUSR2, &s_sig, NULL);
pid = getpid();
ft_printf("pid %i\n", pid);
while (369)
pause();
}
void handler(int signum, siginfo_t *info, void *context)
{
static unsigned char c = 0x0;
static int bit = 0;
(void)context;
if (signum == SIGUSR1)
c |= 0x1;
if (++bit == 8)
{
write(1, &c, 1);
c = 0x0;
bit = 0;
}
c <<= 0x1;
if (signum == SIGUSR1)
kill(info->si_pid, SIGUSR1);
else if (signum == SIGUSR2)
kill(info->si_pid, SIGUSR2);
}