-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.c
More file actions
71 lines (63 loc) · 1.53 KB
/
server.c
File metadata and controls
71 lines (63 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bguzel <bguzel@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/30 18:32:01 by bguzel #+# #+# */
/* Updated: 2023/01/31 18:58:33 by bguzel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i])
write(1, &str[i++], 1);
}
void ft_putnbr(int nb)
{
if (nb < 0)
{
ft_putchar('-');
nb = -nb;
}
if (nb >= 10)
{
ft_putnbr(nb / 10);
nb = nb % 10;
}
if (nb < 10)
ft_putchar(nb + 48);
}
void sender(int number)
{
static char j;
static int i = 128;
if (number == SIGUSR1)
j += i;
i = i / 2;
if (i == 0)
{
write(1, &j, 1);
i = 128;
j = 0;
}
}
int main(void)
{
ft_putstr("pid : ");
ft_putnbr(getpid());
ft_putstr("\n");
signal(SIGUSR1, &sender);
signal(SIGUSR2, &sender);
while (1)
continue ;
return (0);
}