-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.c
61 lines (54 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fatkeski <fatkeski@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/25 16:43:34 by fatkeski #+# #+# */
/* Updated: 2024/02/25 16:54:48 by fatkeski ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
static void ft_putpid(pid_t n)
{
char c;
if (n > 9)
{
ft_putpid((n / 10));
ft_putpid((n % 10));
}
else
{
c = 48 + n;
write(1, &c, 1);
}
}
static void signal_handler(int signal)
{
static char chr;
static int i;
i++;
if (signal == SIGUSR1)
chr = chr | 1;
if (i == 8)
{
write(1, &chr, 1);
i = 0;
chr = 0;
}
chr = chr << 1;
}
int main(void)
{
pid_t server_id;
server_id = getpid();
ft_putpid(server_id);
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
while (1)
{
pause();
}
return (0);
}