Skip to content

Instantly share code, notes, and snippets.

@Andrei-Pozolotin
Forked from nicoulaj/java-signals-test.sh
Created November 21, 2016 18:08
Show Gist options
  • Save Andrei-Pozolotin/34f477dc1f60e0eb01ba6a7bd0b5a124 to your computer and use it in GitHub Desktop.
Save Andrei-Pozolotin/34f477dc1f60e0eb01ba6a7bd0b5a124 to your computer and use it in GitHub Desktop.
What signals can your JRE handle ?
#!/bin/bash
# Get temp dir
tmpdir=$(mktemp -d)
# Generate test
cat > ${tmpdir}/ListenToSignal.java <<EOF
import sun.misc.Signal;
import sun.misc.SignalHandler;
public class ListenToSignal {
public static void main(String[] args) {
try {
Signal.handle(new Signal(args[0]), new SignalHandler() {
public void handle(Signal sig) {
System.out.println(sig.getName() + ": yes");
System.exit(0);
}
});
Thread.sleep(5000L);
System.out.println(args[0] + ": no");
} catch (Throwable t) {
System.out.println(args[0] + ": no (" + t.getMessage() + ")");
}
System.exit(1);
}
}
EOF
# Compile test
javac ${tmpdir}/ListenToSignal.java &>/dev/null
# Get signals, test each one of them
for signal in $(kill -l | grep -Po '(?<=SIG)[^\s]+'); do
java -cp ${tmpdir} ListenToSignal $signal & # Start program in background
sleep 2 # Make sure it is ready
kill -s $signal $! &>/dev/null # Send signal
wait # Wait to termination
done
$ cat /etc/issue
Arch Linux \r (\l)
$ uname -a
Linux storm 3.5.4-1-ARCH #1 SMP PREEMPT Sat Sep 15 08:12:04 CEST 2012 x86_64 GNU/Linux
$ java -version
java version "1.7.0_07"
Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)
$ ./java-signals-test.sh
HUP: yes
INT: no
QUIT: no (Signal already used by VM or OS: SIGQUIT)
ILL: no (Signal already used by VM or OS: SIGILL)
TRAP: yes
ABRT: yes
BUS: yes
FPE: no (Signal already used by VM or OS: SIGFPE)
KILL: no (Signal already used by VM or OS: SIGKILL)
USR1: no (Signal already used by VM or OS: SIGUSR1)
SEGV: no (Signal already used by VM or OS: SIGSEGV)
USR2: yes
PIPE: yes
ALRM: yes
TERM: yes
STKFLT: yes
CHLD: yes
CONT: yes
STOP: no (Signal already used by VM or OS: SIGSTOP)
TSTP: yes
TTIN: yes
TTOU: yes
URG: yes
XCPU: yes
XFSZ: yes
VTALRM: yes
PROF: yes
WINCH: yes
IO: yes
PWR: yes
SYS: yes
RTMIN: no (Unknown signal: RTMIN)
RTMIN+1: no (Unknown signal: RTMIN+1)
RTMIN+2: no (Unknown signal: RTMIN+2)
RTMIN+3: no (Unknown signal: RTMIN+3)
RTMIN+4: no (Unknown signal: RTMIN+4)
RTMIN+5: no (Unknown signal: RTMIN+5)
RTMIN+6: no (Unknown signal: RTMIN+6)
RTMIN+7: no (Unknown signal: RTMIN+7)
RTMIN+8: no (Unknown signal: RTMIN+8)
RTMIN+9: no (Unknown signal: RTMIN+9)
RTMIN+10: no (Unknown signal: RTMIN+10)
RTMIN+11: no (Unknown signal: RTMIN+11)
RTMIN+12: no (Unknown signal: RTMIN+12)
RTMIN+13: no (Unknown signal: RTMIN+13)
RTMIN+14: no (Unknown signal: RTMIN+14)
RTMIN+15: no (Unknown signal: RTMIN+15)
RTMAX-14: no (Unknown signal: RTMAX-14)
RTMAX-13: no (Unknown signal: RTMAX-13)
RTMAX-12: no (Unknown signal: RTMAX-12)
RTMAX-11: no (Unknown signal: RTMAX-11)
RTMAX-10: no (Unknown signal: RTMAX-10)
RTMAX-9: no (Unknown signal: RTMAX-9)
RTMAX-8: no (Unknown signal: RTMAX-8)
RTMAX-7: no (Unknown signal: RTMAX-7)
RTMAX-6: no (Unknown signal: RTMAX-6)
RTMAX-5: no (Unknown signal: RTMAX-5)
RTMAX-4: no (Unknown signal: RTMAX-4)
RTMAX-3: no (Unknown signal: RTMAX-3)
RTMAX-2: no (Unknown signal: RTMAX-2)
RTMAX-1: no (Unknown signal: RTMAX-1)
RTMAX: no (Unknown signal: RTMAX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment