-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_bonus.c
52 lines (46 loc) · 1.67 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
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aaslan <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 01:03:43 by aaslan #+# #+# */
/* Updated: 2023/01/04 16:27:36 by aaslan ### ########.fr */
/* */
/* ************************************************************************** */
#include "utilities/utilities.h"
void ft_print_server_id(int server_id)
{
ft_print_string("Server ID : ");
ft_print_integer(server_id);
ft_print_char('\n');
}
void ft_receive_signal(int signal, siginfo_t *sig_info, void *context)
{
static int bit_index = 0;
static char character = 0;
(void)context;
if (signal == SIGUSR1)
character = character | 1 << bit_index;
bit_index++;
if (bit_index == 8)
{
ft_print_char(character);
bit_index = 0;
character = 0;
kill(sig_info->si_pid, SIGUSR1);
}
}
int main(void)
{
struct sigaction struct_sigaction;
struct_sigaction.sa_flags = SA_SIGINFO;
struct_sigaction.sa_sigaction = ft_receive_signal;
ft_print_server_id(getpid());
sigaction(SIGUSR1, &struct_sigaction, NULL);
sigaction(SIGUSR2, &struct_sigaction, NULL);
while (1)
pause();
return (0);
}