-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.c
72 lines (64 loc) · 2.46 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oqaroot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/17 17:20:28 by oqaroot #+# #+# */
/* Updated: 2024/10/17 17:20:30 by oqaroot ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putstr_fd(char *s, int fd)
{
write(fd, s, ft_strlen(s));
}
size_t ft_strlen(const char *s)
{
size_t i;
i = 0;
while (s[i])
i++;
return (i);
}
void print_intro(int pid)
{
ft_putstr("\n\033[1;33m");
ft_putstr("███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ \n");
ft_putstr("██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗\n");
ft_putstr("███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝\n");
ft_putstr("╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗\n");
ft_putstr("███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║\n");
ft_putstr("╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝\n");
ft_putstr("Process ID: \033[1;34m");
ft_putnbr(pid);
ft_putstr("\033[0m\t\n");
}
void handler(int sig)
{
static int i = 0;
static unsigned char c = 0;
if (sig == SIGUSR2)
c = c << 1;
else if (sig == SIGUSR1)
c = (c << 1) | 0b00000001;
i++;
if (i == 8)
{
ft_putchar(c);
i = 0;
c = 0;
}
}
int main(void)
{
ft_putnbr(getpid());
print_intro(getpid());
while (1)
{
signal(SIGUSR1, handler);
signal(SIGUSR2, handler);
}
return (0);
}