-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
54 lines (49 loc) · 1.53 KB
/
Copy pathserver.c
File metadata and controls
54 lines (49 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtrinida <gtrinida@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 18:16:21 by gtrinida #+# #+# */
/* Updated: 2022/03/11 20:36:51 by gtrinida ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void print(int signal, siginfo_t *info, void *nothing)
{
static int bit;
static unsigned char sym;
(void)nothing;
if (signal == SIGUSR1)
signal = 0;
else
signal = 1;
sym += signal << bit;
bit++;
if (bit == 8)
{
if (sym == 0)
if (kill(info->si_pid, SIGUSR2))
{
ft_putstr_fd("\nError\n", 1);
exit(1);
}
ft_putchar_fd(sym, 1);
bit = 0;
sym = 0;
}
}
int main(void)
{
struct sigaction sa;
sa.sa_flags = SA_SIGINFO;
sa.sa_sigaction = print;
ft_putstr_fd("Server PID: ", 1);
ft_putnbr_fd(getpid(), 1);
write(1, "\n", 1);
sigaction(SIGUSR2, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
while (1)
pause();
}