Repository navigation
Expand file tree
/
Copy pathserver.c
More file actions
46 lines (41 loc) · 1.38 KB
/
Copy pathserver.c
File metadata and controls
46 lines (41 loc) · 1.38 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* server.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: duzun <davut@uzun.ist> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/02 18:05:40 by duzun #+# #+# */
/* Updated: 2022/09/08 00:13:01 by duzun ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk.h"
void ft_handler(int signal)
{
static int bit;
static int i;
if (signal == SIGUSR1)
i |= (0x01 << bit);
bit++;
if (bit == 8)
{
write(1, &i, 1);
bit = 0;
i = 0;
}
}
int main(void)
{
pid_t pid;
pid = getpid();
ft_putstr_fd("\033[35mSend messages from Client to Server with PID.\n\
\033[32;40mServer [PID = \033[31m", 1);
ft_putnbr_fd(pid, 1);
ft_putstr_fd("\033[32m]\033[37;40;0m\n", 1);
while (1)
{
signal(SIGUSR1, ft_handler);
signal(SIGUSR2, ft_handler);
pause();
}
}