Repository navigation
Expand file tree
/
Copy pathserver.c
More file actions
59 lines (52 loc) · 1.43 KB
/
Copy pathserver.c
File metadata and controls
59 lines (52 loc) · 1.43 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.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gsap <gsap@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/26 13:15:53 by gsap #+# #+# */
/* Updated: 2021/07/29 11:46:58 by gsap ### ########.fr */
/* */
/* ************************************************************************** */
#include "server.h"
char g_c;
void id_process(void)
{
int i;
i = getpid();
write(1, "PID Server: ", 12);
ft_putnbr(i);
write(1, "\n", 1);
return ;
}
void handle_sigusr(int sig)
{
if (sig == SIGUSR1)
g_c = '0';
if (sig == SIGUSR2)
g_c = '1';
}
int main(void)
{
char s[9];
int i;
i = 0;
id_process();
if (signal(SIGUSR1, handle_sigusr) != 0)
return (0);
if (signal(SIGUSR2, handle_sigusr) != 0)
return (0);
while (1)
{
pause();
s[i++] = g_c;
if (i == 8)
{
ft_putchar((char)ft_bin_to_dec(s));
s[i] = 0;
i = 0;
}
}
return (0);
}