-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.c
74 lines (67 loc) · 1.77 KB
/
client.c
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
73
74
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* client.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: omkuzu <omkuzu@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/17 16:36:08 by omkuzu #+# #+# */
/* Updated: 2024/12/17 17:02:32 by omkuzu ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
static int ft_atoi(const char *str)
{
int i;
int result;
i = 0;
result = 0;
while (str[i] >= '0' && str[i] <= '9')
{
result = (result * 10) + (str[i] - 48);
i++;
}
return (result);
}
static void send_signal(pid_t id, char *message)
{
int i;
int j;
char result;
i = 0;
while (message[i] != '\0')
{
j = 7;
while (j >= 0)
{
result = (message[i] >> j) & 1;
if (result == 1)
kill(id, SIGUSR1);
else if (result == 0)
kill(id, SIGUSR2);
usleep(50);
j--;
}
i++;
}
}
int main(int argc, char *argv[])
{
pid_t server_id;
if (argc == 3)
{
server_id = ft_atoi(argv[1]);
if (server_id <= 0)
{
write(1, "Error: Invalid server PID.\n", 28);
return (1);
}
send_signal(server_id, argv[2]);
}
else
write(1, "İstenen bagimsiz degisken sayisi girilmedi\n", 43);
return (0);
}