-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
15 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/09 15:02:14 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/10 13:30:49 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 13:38:56 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -44,12 +44,12 @@ void send_signal(int pid, unsigned char character) | |
} | ||
} | ||
|
||
void handle_read_receipt(int signal) | ||
void handle_read_receipt(int signal) | ||
{ | ||
if (signal == SIGUSR1) | ||
ft_printf("Received bit 1\n"); | ||
ft_printf("Received bit 1\n"); | ||
else if (signal == SIGUSR2) | ||
ft_printf("Received bit 0\n"); | ||
ft_printf("Received bit 0\n"); | ||
} | ||
|
||
/** | ||
|
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) | |
const char *message; | ||
int i; | ||
|
||
signal(SIGUSR1, handle_read_receipt); | ||
signal(SIGUSR1, handle_read_receipt); | ||
signal(SIGUSR2, handle_read_receipt); | ||
if (argc != 3) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/09 15:02:13 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/09 16:49:47 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 13:38:51 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -39,8 +39,8 @@ | |
*/ | ||
void handle_signal(int signal) | ||
{ | ||
static unsigned char current_char; | ||
static int bit_index; | ||
static unsigned char current_char; | ||
static int bit_index; | ||
|
||
current_char |= (signal == SIGUSR1); | ||
bit_index++; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: lgaudin <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2023/06/09 15:02:13 by lgaudin #+# #+# */ | ||
/* Updated: 2023/06/10 13:12:52 by lgaudin ### ########.fr */ | ||
/* Updated: 2023/06/10 13:38:49 by lgaudin ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -38,10 +38,10 @@ | |
*/ | ||
void handle_signal(int signal, siginfo_t *info, void *context) | ||
{ | ||
static unsigned char current_char; | ||
static int bit_index; | ||
static unsigned char current_char; | ||
static int bit_index; | ||
|
||
(void)context; | ||
(void)context; | ||
current_char |= (signal == SIGUSR1); | ||
bit_index++; | ||
if (bit_index == 8) | ||
|
@@ -53,17 +53,17 @@ void handle_signal(int signal, siginfo_t *info, void *context) | |
else | ||
current_char <<= 1; | ||
if (signal == SIGUSR1) | ||
kill(info->si_pid, SIGUSR1); | ||
kill(info->si_pid, SIGUSR1); | ||
else if (signal == SIGUSR2) | ||
kill(info->si_pid, SIGUSR2); | ||
kill(info->si_pid, SIGUSR2); | ||
} | ||
|
||
/** | ||
* @brief Prints its program's PID and calls the signal handlers. | ||
*/ | ||
int main(void) | ||
{ | ||
struct sigaction sa; | ||
struct sigaction sa; | ||
|
||
sa.sa_sigaction = &handle_signal; | ||
sa.sa_flags = SA_SIGINFO; | ||
|