dans server remplace signal par sigaction pour recuperer sender pid ok

This commit is contained in:
hugogogo
2021-08-31 12:41:23 +02:00
parent a5f922ed6e
commit a988550a35
7 changed files with 208 additions and 167 deletions

Binary file not shown.

Binary file not shown.

BIN
client

Binary file not shown.

BIN
server

Binary file not shown.

View File

@@ -9,6 +9,7 @@ int usage(void)
void send_char(int server_pid, char c)
{
int mask;
mask = 1 << 6;
while (mask != 0)
{
@@ -17,7 +18,7 @@ void send_char(int server_pid, char c)
if ((c & mask) == 0)
kill(server_pid, SIGUSR2);
mask >>= 1;
usleep(20);
usleep(1);
}
}
@@ -36,5 +37,6 @@ int main(int ac, char **av)
if (ac != 3)
return (usage());
send_message(ft_atoi(av[1]), av[2]);
ft_putnbrendl((int)getpid());
return (0);
}

View File

@@ -1,15 +1,19 @@
#include "minitalk.h"
void sig_handler_1(int sig_num)
void sig_handler_1(int sig_num, siginfo_t *info, void *context)
{
(void)sig_num;
(void)context;
kill(info->sa__pid, SIGUSR1);
message.character ^= 1 << (6 - message.count_bits);
message.count_bits++;
}
void sig_handler_2(int sig_num)
void sig_handler_2(int sig_num, siginfo_t *info, void *context)
{
(void)sig_num;
(void)context;
kill(info->sa__pid, SIGUSR2);
message.count_bits++;
}
@@ -38,8 +42,15 @@ void concat_msg()
int main()
{
signal(SIGUSR1, sig_handler_1);
signal(SIGUSR2, sig_handler_2);
struct sigaction act_1;
struct sigaction act_2;
act_1.sa_flags = SA_SIGINFO;
act_1.sa_sigaction = sig_handler_1;
act_2.sa_flags = SA_SIGINFO;
act_2.sa_sigaction = sig_handler_2;
sigaction(SIGUSR1, &act_1, NULL);
sigaction(SIGUSR2, &act_2, NULL);
ft_putnbrendl((int)getpid());
init_message();
while (1)
@@ -48,6 +59,9 @@ int main()
}
/*
** # # # # # # # # # # # # # # # # # # # #
** INSTRUCTIONS
**
** allowed functions :
** - write
** - signal
@@ -63,19 +77,53 @@ int main()
** - usleep
** - exit
**
**
** cmm
** deii
** enlc
** ctlr
** iiio
** 0.0010
** 10
**
** you can only use two signals :
** - SIGUSR1
** - SIGUSR2
**
**
** # # # # # # # # # # # # # # # # # # # #
** ressources
**
** use of getpid : https://www.includehelp.com/c/getpid-and-getppid-functions-in-c-linux.aspx
** use of signal : https://linuxhint.com/signal_handlers_c_programming_language
** use of sigaction : https://stackoverflow.com/a/17572787/9497573
** standard signal vs real time signals (with queue option) : https://www.softprayog.in/programming/posix-real-time-signals-in-linux
**
**
** # # # # # # # # # # # # # # # # # # # #
** UNITS PREFIX
**
** times in seconds, deci, centi, milli, micros and nano :
**
** c m m
** d e i i n
** e n l c a
** c t l r n
** i i i o o
**
** 0 . 0 0 1 0 0
**
**
** # # # # # # # # # # # # # # # # # # # #
** CODE TO CALCULATE TIME IN MICROSECONDS
**
** found here https://stackoverflow.com/questions/5833094/get-a-timestamp-in-c-in-microseconds
**
** #include <stdint.h>
** #include <sys/time.h>
** uint64_t micros() {
** struct timeval tv;
** gettimeofday(&tv,NULL);
** return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
** }
** uint64_t t1;
** uint64_t t2;
**
**
** # # # # # # # # # # # # # # # # # # # #
** BINARY NUMBERS
**
** 1 000 0
** 2 001 1 2
** 3 002 10
@@ -204,5 +252,6 @@ int main()
** 126 125 1111101
** 127 126 1111110
** 128 127 1111111 64
** # # # # # # # # # # # # # # # # # # # #
**
*/

View File

@@ -1,10 +0,0 @@
18112
cnealin azelj aze .
cnealin azelj aze .
cnealin azelj aze .
cnealin azelj aze
cnealin azelj aze.....
21377
cnealin azelj aze.....
cnealin azelj aze
salut heuuu