42_minitalk/client_src/main.c
2023-01-24 15:29:14 +01:00

53 lines
1.4 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/20 17:06:30 by cchauvet #+# #+# */
/* Updated: 2023/01/20 18:36:25 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
#include "../libftx/libftx.h"
void ft_char2signal(int pid, char c)
{
size_t i;
i = sizeof(char) * 8;
while (i > 0)
{
if ((c >> (i - 1)) & 1)
kill(pid, SIGUSR2);
else
kill(pid, SIGUSR1);
usleep(5);
i--;
}
}
int main(int ac, char **av)
{
int pid;
size_t i;
if (ac != 3 || !ft_isnum(av[1]))
{
ft_printf("Argument error !");
return (1);
}
pid = ft_atoi(av[1]);
kill(pid, SIGUSR2);
i = 0;
while (av[2][i] != '\0')
{
ft_char2signal(pid, av[2][i]);
i++;
}
ft_char2signal(pid, '\0');
return (0);
}