diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-05-25 19:42:24 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-05-25 19:42:24 +0200 |
commit | 589ec07d1ec29e9e33714fcc0f213e79c1f36a9a (patch) | |
tree | 785e8d77493c0eeac4ea94799daf24f75ad2016d /02_exercise/signal_handler.c | |
parent | 41775b83ad93264b487bf0dc353b145922ee6d73 (diff) | |
download | betriebssysteme-589ec07d1ec29e9e33714fcc0f213e79c1f36a9a.tar.gz betriebssysteme-589ec07d1ec29e9e33714fcc0f213e79c1f36a9a.zip |
DO NOT MERGE, use previous. Trying to get ctrl-z to work.. no success yet, maybe breaks stufffixing_signals
Diffstat (limited to '02_exercise/signal_handler.c')
-rw-r--r-- | 02_exercise/signal_handler.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/02_exercise/signal_handler.c b/02_exercise/signal_handler.c new file mode 100644 index 0000000..e135739 --- /dev/null +++ b/02_exercise/signal_handler.c @@ -0,0 +1,30 @@ +#include "signal_handler.h" + +#include <wait.h> +#include <stdio.h> +#include <unistd.h> + +void signal_handler(int signal) { + if (signal == SIGINT) { + interrupt_issued = 1; + } else if (signal == SIGTSTP) { + stop_issued = 1; + kill(getpid(), SIGINT); + } +} + +void handle_interrupt(pid_t pid) { + int status; + if (stop_issued) { + stop_issued = 0; + interrupt_issued = 0; + } else if (interrupt_issued) { + interrupt_issued = 0; + kill(pid, SIGKILL); + waitpid(pid, &status, 0); + printf("Killed [%ld]\n", (long)pid); + return; + } + kill(pid, SIGCONT); + printf("[%ld]\n", (long)pid); +}
\ No newline at end of file |