From e34f07dc8bd8db122616b27329404947b49b0d3b Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Mon, 17 Jun 2024 17:00:33 +0200 Subject: Note: Sending signals to C programs --- .../2024-06-17-sending-signals-to-c-programs.md | 85 +++++++++++----------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'content/notes') diff --git a/content/notes/2024-06-17-sending-signals-to-c-programs.md b/content/notes/2024-06-17-sending-signals-to-c-programs.md index 94f0b94..bd4a895 100644 --- a/content/notes/2024-06-17-sending-signals-to-c-programs.md +++ b/content/notes/2024-06-17-sending-signals-to-c-programs.md @@ -9,8 +9,8 @@ draft: false For simple and easy IPC to the C program we can use signals. https://www.man7.org/linux/man-pages/man7/signal.7.html -Only two user defined signals are available but you can hijack other ones even -though this is really not advisable. +Only two user defined signals are available (`SIGUSR1` and `SIGUSR2`) but you +can hijack other ones even though this is really not advisable. ```c // signal.c @@ -39,43 +39,44 @@ Compile with `gcc -o signal signal.c` and run the program with `./signal` and then from another terminal send the signal to the program with `kill -10 $(pidof signal)` which should print out `Signal received: 10`. -| Signal | x86/ARM | Alpha/ | MIPS | PARISC | Notes | -|-----------|---------|--------|------|--------|---------------| -| SIGHUP | 1 | 1 | 1 | 1 | | -| SIGINT | 2 | 2 | 2 | 2 | | -| SIGQUIT | 3 | 3 | 3 | 3 | | -| SIGILL | 4 | 4 | 4 | 4 | | -| SIGTRAP | 5 | 5 | 5 | 5 | | -| SIGABRT | 6 | 6 | 6 | 6 | | -| SIGIOT | 6 | 6 | 6 | 6 | | -| SIGBUS | 7 | 10 | 10 | 10 | | -| SIGEMT | - | 7 | 7 | - | | -| SIGFPE | 8 | 8 | 8 | 8 | | -| SIGKILL | 9 | 9 | 9 | 9 | | -| SIGUSR1 | 10 | 30 | 16 | 16 | | -| SIGSEGV | 11 | 11 | 11 | 11 | | -| SIGUSR2 | 12 | 31 | 17 | 17 | | -| SIGPIPE | 13 | 13 | 13 | 13 | | -| SIGALRM | 14 | 14 | 14 | 14 | | -| SIGTERM | 15 | 15 | 15 | 15 | | -| SIGSTKFLT | 16 | - | - | 7 | | -| SIGCHLD | 17 | 20 | 18 | 18 | | -| SIGCLD | - | - | 18 | - | | -| SIGCONT | 18 | 19 | 25 | 26 | | -| SIGSTOP | 19 | 17 | 23 | 24 | | -| SIGTSTP | 20 | 18 | 24 | 25 | | -| SIGTTIN | 21 | 21 | 26 | 27 | | -| SIGTTOU | 22 | 22 | 27 | 28 | | -| SIGURG | 23 | 16 | 21 | 29 | | -| SIGXCPU | 24 | 24 | 30 | 12 | | -| SIGXFSZ | 25 | 25 | 31 | 30 | | -| SIGVTALRM | 26 | 26 | 28 | 20 | | -| SIGPROF | 27 | 27 | 29 | 21 | | -| SIGWINCH | 28 | 28 | 20 | 23 | | -| SIGIO | 29 | 23 | 22 | 22 | | -| SIGPOLL | | | | | Same as SIGIO | -| SIGPWR | 30 | 29/- | 19 | 19 | | -| SIGINFO | - | 29/- | - | - | | -| SIGLOST | - | -/29 | - | - | | -| SIGSYS | 31 | 12 | 12 | 31 | | -| SIGUNUSED | 31 | - | - | 31 | | +| Signal | x86/ARM | Alpha/ | MIPS | PARISC | Notes | +|-------------|---------|--------|--------|--------|---------------| +| SIGHUP | 1 | 1 | 1 | 1 | | +| SIGINT | 2 | 2 | 2 | 2 | | +| SIGQUIT | 3 | 3 | 3 | 3 | | +| SIGILL | 4 | 4 | 4 | 4 | | +| SIGTRAP | 5 | 5 | 5 | 5 | | +| SIGABRT | 6 | 6 | 6 | 6 | | +| SIGIOT | 6 | 6 | 6 | 6 | | +| SIGBUS | 7 | 10 | 10 | 10 | | +| SIGEMT | - | 7 | 7 | - | | +| SIGFPE | 8 | 8 | 8 | 8 | | +| SIGKILL | 9 | 9 | 9 | 9 | | +| **SIGUSR1** | **10** | **30** | **16** | **16** | | +| SIGSEGV | 11 | 11 | 11 | 11 | | +| **SIGUSR2** | **12** | **31** | **17** | **17** | | +| SIGPIPE | 13 | 13 | 13 | 13 | | +| SIGALRM | 14 | 14 | 14 | 14 | | +| SIGTERM | 15 | 15 | 15 | 15 | | +| SIGSTKFLT | 16 | - | - | 7 | | +| SIGCHLD | 17 | 20 | 18 | 18 | | +| SIGCLD | - | - | 18 | - | | +| SIGCONT | 18 | 19 | 25 | 26 | | +| SIGSTOP | 19 | 17 | 23 | 24 | | +| SIGTSTP | 20 | 18 | 24 | 25 | | +| SIGTTIN | 21 | 21 | 26 | 27 | | +| SIGTTOU | 22 | 22 | 27 | 28 | | +| SIGURG | 23 | 16 | 21 | 29 | | +| SIGXCPU | 24 | 24 | 30 | 12 | | +| SIGXFSZ | 25 | 25 | 31 | 30 | | +| SIGVTALRM | 26 | 26 | 28 | 20 | | +| SIGPROF | 27 | 27 | 29 | 21 | | +| SIGWINCH | 28 | 28 | 20 | 23 | | +| SIGIO | 29 | 23 | 22 | 22 | | +| SIGPOLL | | | | | Same as SIGIO | +| SIGPWR | 30 | 29/- | 19 | 19 | | +| SIGINFO | - | 29/- | - | - | | +| SIGLOST | - | -/29 | - | - | | +| SIGSYS | 31 | 12 | 12 | 31 | | +| SIGUNUSED | 31 | - | - | 31 | | + -- cgit v1.2.3