-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_bonus.c
More file actions
59 lines (52 loc) · 1.59 KB
/
server_bonus.c
File metadata and controls
59 lines (52 loc) · 1.59 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
56
57
58
59
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alisharu <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/11/22 21:06:08 by alisharu #+# #+# */
/* Updated: 2025/11/22 21:06:11 by alisharu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_minitalk.h"
unsigned char *g_out = 0;
void man_signal(int signal, siginfo_t *info, void *p)
{
static int i = 0;
static unsigned char binary;
static unsigned char bit;
(void)p;
binary = (signal == SIGUSR1);
bit = bit | (binary << i);
i++;
if (i == 8)
{
g_out = ft_strjoincharacter(g_out, bit);
if (bit == '\0')
{
ft_printf("%s", g_out);
kill(info->si_pid, SIGUSR1);
free (g_out);
g_out = 0;
}
bit = 0;
i = 0;
}
}
void ft_sig(void)
{
struct sigaction a;
a.sa_sigaction = &man_signal;
a.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &a, NULL);
sigaction(SIGUSR2, &a, NULL);
}
int main(void)
{
ft_printf("Your pid is: %d\n", getpid());
ft_sig();
while (1)
pause();
return (0);
}