blob: d24773caaab56cdb5580483b6363de612c7d335f (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/09 03:36:54 by kdx #+# #+# */
/* Updated: 2022/10/12 05:40:57 by kdx ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft/libft.h"
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
static void send(const unsigned char *s, pid_t pid)
{
size_t bit;
int sig;
size_t i;
i = 0;
while (1)
{
bit = 0;
while (bit < 8)
{
sig = SIGUSR1;
if (s[i] & (1 << bit))
sig = SIGUSR2;
kill(pid, sig);
usleep(50 + i / 100);
bit++;
}
if (s[i] == '\0')
break ;
i++;
}
}
int main(int argc, char **argv)
{
pid_t server_pid;
if (argc != 3)
return (1 | ft_dprintf(2, "usage: client <server PID> <string>\n"));
server_pid = ft_atoi(argv[1]);
send((const unsigned char *)argv[2], server_pid);
return (0);
}
|