-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_bonus.c
49 lines (44 loc) · 1.47 KB
/
server_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jilai <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/28 15:11:55 by jilai #+# #+# */
/* Updated: 2024/04/28 15:11:57 by jilai ### ########.fr */
/* */
/* ************************************************************************** */
#include "server_bonus.h"
void handle_signal(int sig, siginfo_t *i, void *context)
{
static unsigned char bit[2];
(void)i;
(void)context;
if (!bit[1])
bit[1] = '0';
bit[0] |= (sig == SIGUSR1);
bit[1]++;
if (bit[1] == '8')
{
ft_printf("%c", bit[0]);
bit[1] = '0';
if (bit[0] == '\0')
kill(i->si_pid, SIGUSR1);
bit[0] = 0;
}
else
bit[0] <<= 1;
}
int main(void)
{
struct sigaction s;
ft_printf("Server PID : %i\n", getpid());
s.sa_sigaction = handle_signal;
s.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &s, NULL);
sigaction(SIGUSR2, &s, NULL);
while (1)
pause();
return (0);
}