dans server remplace signal par sigaction pour recuperer sender pid ok
This commit is contained in:
BIN
builds/client.o
BIN
builds/client.o
Binary file not shown.
BIN
builds/server.o
BIN
builds/server.o
Binary file not shown.
@@ -9,6 +9,7 @@ int usage(void)
|
|||||||
void send_char(int server_pid, char c)
|
void send_char(int server_pid, char c)
|
||||||
{
|
{
|
||||||
int mask;
|
int mask;
|
||||||
|
|
||||||
mask = 1 << 6;
|
mask = 1 << 6;
|
||||||
while (mask != 0)
|
while (mask != 0)
|
||||||
{
|
{
|
||||||
@@ -17,7 +18,7 @@ void send_char(int server_pid, char c)
|
|||||||
if ((c & mask) == 0)
|
if ((c & mask) == 0)
|
||||||
kill(server_pid, SIGUSR2);
|
kill(server_pid, SIGUSR2);
|
||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
usleep(20);
|
usleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,5 +37,6 @@ int main(int ac, char **av)
|
|||||||
if (ac != 3)
|
if (ac != 3)
|
||||||
return (usage());
|
return (usage());
|
||||||
send_message(ft_atoi(av[1]), av[2]);
|
send_message(ft_atoi(av[1]), av[2]);
|
||||||
|
ft_putnbrendl((int)getpid());
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
361
srcs/server.c
361
srcs/server.c
@@ -1,15 +1,19 @@
|
|||||||
#include "minitalk.h"
|
#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)sig_num;
|
||||||
|
(void)context;
|
||||||
|
kill(info->sa__pid, SIGUSR1);
|
||||||
message.character ^= 1 << (6 - message.count_bits);
|
message.character ^= 1 << (6 - message.count_bits);
|
||||||
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)sig_num;
|
||||||
|
(void)context;
|
||||||
|
kill(info->sa__pid, SIGUSR2);
|
||||||
message.count_bits++;
|
message.count_bits++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,8 +42,15 @@ void concat_msg()
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
signal(SIGUSR1, sig_handler_1);
|
struct sigaction act_1;
|
||||||
signal(SIGUSR2, sig_handler_2);
|
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());
|
ft_putnbrendl((int)getpid());
|
||||||
init_message();
|
init_message();
|
||||||
while (1)
|
while (1)
|
||||||
@@ -48,161 +59,199 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** allowed functions :
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
** - write
|
** INSTRUCTIONS
|
||||||
** - signal
|
**
|
||||||
** - sigemptyset
|
** allowed functions :
|
||||||
** - sigaddset
|
** - write
|
||||||
** - sigaction
|
** - signal
|
||||||
** - kill
|
** - sigemptyset
|
||||||
** - getpid
|
** - sigaddset
|
||||||
** - malloc
|
** - sigaction
|
||||||
** - free
|
** - kill
|
||||||
** - pause
|
** - getpid
|
||||||
** - sleep
|
** - malloc
|
||||||
** - usleep
|
** - free
|
||||||
** - exit
|
** - pause
|
||||||
|
** - sleep
|
||||||
|
** - usleep
|
||||||
|
** - exit
|
||||||
|
**
|
||||||
|
** you can only use two signals :
|
||||||
|
** - SIGUSR1
|
||||||
|
** - SIGUSR2
|
||||||
**
|
**
|
||||||
**
|
**
|
||||||
** cmm
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
** deii
|
** ressources
|
||||||
** enlc
|
|
||||||
** ctlr
|
|
||||||
** iiio
|
|
||||||
** 0.0010
|
|
||||||
** 10
|
|
||||||
**
|
**
|
||||||
** you can only use two signals :
|
** use of getpid : https://www.includehelp.com/c/getpid-and-getppid-functions-in-c-linux.aspx
|
||||||
** - SIGUSR1
|
** use of signal : https://linuxhint.com/signal_handlers_c_programming_language
|
||||||
** - SIGUSR2
|
** 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
|
||||||
**
|
**
|
||||||
** 1 000 0
|
**
|
||||||
** 2 001 1 2
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
** 3 002 10
|
** UNITS PREFIX
|
||||||
** 4 003 11 2
|
**
|
||||||
** 5 004 100
|
** times in seconds, deci, centi, milli, micros and nano :
|
||||||
** 6 005 101
|
**
|
||||||
** 7 006 110
|
** c m m
|
||||||
** 8 007 111 4
|
** d e i i n
|
||||||
** 9 008 1000
|
** e n l c a
|
||||||
** 10 009 1001
|
** c t l r n
|
||||||
** 11 010 1010
|
** i i i o o
|
||||||
** 12 011 1011
|
**
|
||||||
** 13 012 1100
|
** 0 . 0 0 1 0 0
|
||||||
** 14 013 1101
|
**
|
||||||
** 15 014 1110
|
**
|
||||||
** 16 015 1111 8
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
** 17 016 10000
|
** CODE TO CALCULATE TIME IN MICROSECONDS
|
||||||
** 18 017 10001
|
**
|
||||||
** 19 018 10010
|
** found here https://stackoverflow.com/questions/5833094/get-a-timestamp-in-c-in-microseconds
|
||||||
** 20 019 10011
|
**
|
||||||
** 21 020 10100
|
** #include <stdint.h>
|
||||||
** 22 021 10101
|
** #include <sys/time.h>
|
||||||
** 23 022 10110
|
** uint64_t micros() {
|
||||||
** 24 023 10111
|
** struct timeval tv;
|
||||||
** 25 024 11000
|
** gettimeofday(&tv,NULL);
|
||||||
** 26 025 11001
|
** return tv.tv_sec*(uint64_t)1000000+tv.tv_usec;
|
||||||
** 27 026 11010
|
** }
|
||||||
** 28 027 11011
|
** uint64_t t1;
|
||||||
** 29 028 11100
|
** uint64_t t2;
|
||||||
** 30 029 11101
|
**
|
||||||
** 31 030 11110
|
**
|
||||||
** 32 031 11111 16
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
** 33 032 100000
|
** BINARY NUMBERS
|
||||||
** 34 033 100001
|
**
|
||||||
** 35 034 100010
|
** 1 000 0
|
||||||
** 36 035 100011
|
** 2 001 1 2
|
||||||
** 37 036 100100
|
** 3 002 10
|
||||||
** 38 037 100101
|
** 4 003 11 2
|
||||||
** 39 038 100110
|
** 5 004 100
|
||||||
** 40 039 100111
|
** 6 005 101
|
||||||
** 41 040 101000
|
** 7 006 110
|
||||||
** 42 041 101001
|
** 8 007 111 4
|
||||||
** 43 042 101010
|
** 9 008 1000
|
||||||
** 44 043 101011
|
** 10 009 1001
|
||||||
** 45 044 101100
|
** 11 010 1010
|
||||||
** 46 045 101101
|
** 12 011 1011
|
||||||
** 47 046 101110
|
** 13 012 1100
|
||||||
** 48 047 101111
|
** 14 013 1101
|
||||||
** 49 048 110000
|
** 15 014 1110
|
||||||
** 50 049 110001
|
** 16 015 1111 8
|
||||||
** 51 050 110010
|
** 17 016 10000
|
||||||
** 52 051 110011
|
** 18 017 10001
|
||||||
** 53 052 110100
|
** 19 018 10010
|
||||||
** 54 053 110101
|
** 20 019 10011
|
||||||
** 55 054 110110
|
** 21 020 10100
|
||||||
** 56 055 110111
|
** 22 021 10101
|
||||||
** 57 056 111000
|
** 23 022 10110
|
||||||
** 58 057 111001
|
** 24 023 10111
|
||||||
** 59 058 111010
|
** 25 024 11000
|
||||||
** 60 059 111011
|
** 26 025 11001
|
||||||
** 61 060 111100
|
** 27 026 11010
|
||||||
** 62 061 111101
|
** 28 027 11011
|
||||||
** 63 062 111110
|
** 29 028 11100
|
||||||
** 64 063 111111 32
|
** 30 029 11101
|
||||||
** 65 064 1000000
|
** 31 030 11110
|
||||||
** 66 065 1000001
|
** 32 031 11111 16
|
||||||
** 67 066 1000010
|
** 33 032 100000
|
||||||
** 68 067 1000011
|
** 34 033 100001
|
||||||
** 69 068 1000100
|
** 35 034 100010
|
||||||
** 70 069 1000101
|
** 36 035 100011
|
||||||
** 71 070 1000110
|
** 37 036 100100
|
||||||
** 72 071 1000111
|
** 38 037 100101
|
||||||
** 73 072 1001000
|
** 39 038 100110
|
||||||
** 74 073 1001001
|
** 40 039 100111
|
||||||
** 75 074 1001010
|
** 41 040 101000
|
||||||
** 76 075 1001011
|
** 42 041 101001
|
||||||
** 77 076 1001100
|
** 43 042 101010
|
||||||
** 78 077 1001101
|
** 44 043 101011
|
||||||
** 79 078 1001110
|
** 45 044 101100
|
||||||
** 80 079 1001111
|
** 46 045 101101
|
||||||
** 81 080 1010000
|
** 47 046 101110
|
||||||
** 82 081 1010001
|
** 48 047 101111
|
||||||
** 83 082 1010010
|
** 49 048 110000
|
||||||
** 84 083 1010011
|
** 50 049 110001
|
||||||
** 85 084 1010100
|
** 51 050 110010
|
||||||
** 86 085 1010101
|
** 52 051 110011
|
||||||
** 87 086 1010110
|
** 53 052 110100
|
||||||
** 88 087 1010111
|
** 54 053 110101
|
||||||
** 89 088 1011000
|
** 55 054 110110
|
||||||
** 90 089 1011001
|
** 56 055 110111
|
||||||
** 91 090 1011010
|
** 57 056 111000
|
||||||
** 92 091 1011011
|
** 58 057 111001
|
||||||
** 93 092 1011100
|
** 59 058 111010
|
||||||
** 94 093 1011101
|
** 60 059 111011
|
||||||
** 95 094 1011110
|
** 61 060 111100
|
||||||
** 96 095 1011111
|
** 62 061 111101
|
||||||
** 97 096 1100000
|
** 63 062 111110
|
||||||
** 98 097 1100001
|
** 64 063 111111 32
|
||||||
** 99 098 1100010
|
** 65 064 1000000
|
||||||
** 100 099 1100011
|
** 66 065 1000001
|
||||||
** 101 100 1100100
|
** 67 066 1000010
|
||||||
** 102 101 1100101
|
** 68 067 1000011
|
||||||
** 103 102 1100110
|
** 69 068 1000100
|
||||||
** 104 103 1100111
|
** 70 069 1000101
|
||||||
** 105 104 1101000
|
** 71 070 1000110
|
||||||
** 106 105 1101001
|
** 72 071 1000111
|
||||||
** 107 106 1101010
|
** 73 072 1001000
|
||||||
** 108 107 1101011
|
** 74 073 1001001
|
||||||
** 109 108 1101100
|
** 75 074 1001010
|
||||||
** 110 109 1101101
|
** 76 075 1001011
|
||||||
** 111 110 1101110
|
** 77 076 1001100
|
||||||
** 112 111 1101111
|
** 78 077 1001101
|
||||||
** 113 112 1110000
|
** 79 078 1001110
|
||||||
** 114 113 1110001
|
** 80 079 1001111
|
||||||
** 115 114 1110010
|
** 81 080 1010000
|
||||||
** 116 115 1110011
|
** 82 081 1010001
|
||||||
** 117 116 1110100
|
** 83 082 1010010
|
||||||
** 118 117 1110101
|
** 84 083 1010011
|
||||||
** 119 118 1110110
|
** 85 084 1010100
|
||||||
** 120 119 1110111
|
** 86 085 1010101
|
||||||
** 121 120 1111000
|
** 87 086 1010110
|
||||||
** 122 121 1111001
|
** 88 087 1010111
|
||||||
** 123 122 1111010
|
** 89 088 1011000
|
||||||
** 124 123 1111011
|
** 90 089 1011001
|
||||||
** 125 124 1111100
|
** 91 090 1011010
|
||||||
** 126 125 1111101
|
** 92 091 1011011
|
||||||
** 127 126 1111110
|
** 93 092 1011100
|
||||||
** 128 127 1111111 64
|
** 94 093 1011101
|
||||||
|
** 95 094 1011110
|
||||||
|
** 96 095 1011111
|
||||||
|
** 97 096 1100000
|
||||||
|
** 98 097 1100001
|
||||||
|
** 99 098 1100010
|
||||||
|
** 100 099 1100011
|
||||||
|
** 101 100 1100100
|
||||||
|
** 102 101 1100101
|
||||||
|
** 103 102 1100110
|
||||||
|
** 104 103 1100111
|
||||||
|
** 105 104 1101000
|
||||||
|
** 106 105 1101001
|
||||||
|
** 107 106 1101010
|
||||||
|
** 108 107 1101011
|
||||||
|
** 109 108 1101100
|
||||||
|
** 110 109 1101101
|
||||||
|
** 111 110 1101110
|
||||||
|
** 112 111 1101111
|
||||||
|
** 113 112 1110000
|
||||||
|
** 114 113 1110001
|
||||||
|
** 115 114 1110010
|
||||||
|
** 116 115 1110011
|
||||||
|
** 117 116 1110100
|
||||||
|
** 118 117 1110101
|
||||||
|
** 119 118 1110110
|
||||||
|
** 120 119 1110111
|
||||||
|
** 121 120 1111000
|
||||||
|
** 122 121 1111001
|
||||||
|
** 123 122 1111010
|
||||||
|
** 124 123 1111011
|
||||||
|
** 125 124 1111100
|
||||||
|
** 126 125 1111101
|
||||||
|
** 127 126 1111110
|
||||||
|
** 128 127 1111111 64
|
||||||
|
** # # # # # # # # # # # # # # # # # # # #
|
||||||
**
|
**
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user