-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
72 lines (65 loc) · 1.64 KB
/
Copy pathserver.c
File metadata and controls
72 lines (65 loc) · 1.64 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
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: isel-azz <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 12:54:10 by isel-azz #+# #+# */
/* Updated: 2024/05/15 12:54:13 by isel-azz ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
void print_pid(unsigned int pid)
{
if (pid >= 10)
{
print_pid(pid / 10);
pid = pid % 10;
}
if (pid < 10)
ft_putchar(pid + 48);
}
void handler(int sig, siginfo_t *info, void *context)
{
static int i;
static char c;
static int pid;
context = NULL;
if (pid != info->si_pid)
{
c = 0;
i = 0;
pid = info->si_pid;
}
if (sig == SIGUSR1)
c += 1;
i++;
if (i != 8)
c = c << 1;
else
{
write(1, &c, 1);
c = 0;
i = 0;
}
}
int main(int argc, char **argv)
{
struct sigaction sa;
if (argc == 1 && argv)
{
print_pid(getpid());
sa.sa_sigaction = handler;
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
write(1, "\n", 1);
while (1)
pause();
}
return (0);
}