-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.c
58 lines (53 loc) · 1.68 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
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mkhaing <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 01:47:46 by mkhaing #+# #+# */
/* Updated: 2023/11/20 07:36:30 by mkhaing ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void handle_signal(int sig)
{
static char *binary;
static int index;
if (!binary)
{
binary = (char *)malloc(sizeof(char) * 9);
if (!binary)
return ;
index = 0;
binary[8] = '\0';
}
if (sig == SIGUSR1)
binary[index] = '1';
else
binary[index] = '0';
index++;
if (index == 8)
{
ft_printf("%c", ft_binary_to_char(binary));
free(binary);
binary = NULL;
index = 0;
}
}
int main(void)
{
int pid;
pid = getpid();
ft_printf("┓ ╹ • • ┓┓ \n");
ft_printf("┣┓┏┓┏┓ ┏ ┏┳┓┓┏┓┓╋┏┓┃┃┏\n");
ft_printf("┗┛┗┛┛┗ ┛ ┛┗┗┗┛┗┗┗┗┻┗┛┗\n\n");
ft_printf("[PID] : %d\n\n", pid);
while (1)
{
signal(SIGUSR1, handle_signal);
signal(SIGUSR2, handle_signal);
usleep(500);
pause();
}
}