SIGSTOP and SIGTSTP can damage the JVM?
java, jvm, jvm-hotspot, linux, signals
Solution
`SIGSTOP` and `SIGTSTP` are not included in HotSpot JVM's signal handling doesn't mean HotSpot JVM doesn't support them.
It only means there is no special handling for those two signals. Some signals(`SIGSEGV`, `SIGTERM`, etc) are specially handled by HotSpot JVM to implement certain features (implicit null check, shutdown hooks, etc).
The ones not specially handled, they will behave the default way. Hence when HotSpot receives `SIGSTOP` and `SIGTSTP`, it will behave the the default way, which means Pause and Terminal Pause.
In fact, `SIGSTOP` cannot be ignored. From signal(7)'s man page:
The signals `SIGKILL` and `SIGSTOP` cannot be caught, blocked, or ignored.
We can demonstrate this by a simple C program:
#include<stdio.h>
#include<unistd.h>
int main()
{
while(1)
{
printf("Hello World\n");
usleep(900000);
}
return 0;
}
There is no signal handling what so ever for `SIGSTOP` or `SIGTSTP`, but still you can send them to this simple program and they will behave correctly.
By pressing Ctrl+Z will send a `SIGTSTP` signal and by run `kill -19 pid` will send a `SIGSTOP` signal. And the demo program will pause.
In both cases, running a `kill -18 pid` will send `SIGCONT` signal and bring our demo program back to execution.
Problem
In Linux there are two different signals that can be used to pause a process, SIGSTOP and SIGTSTP. Both are not handled by the HotSpot Virtual Machine, SIGSTOP because cannot be caught and SIGTSTP because is not handled by HotSpot. I would like to know if it is safe to send those two signals or, in case it is not safe, what part of the JVM would be affected (e.g. the garbage collector). Note that I don't care about the problems that the program running on the JVM could have, I'm specifically interested in the internals of the JVM. Is it safe to send a STOP/TSTP to the JVM ?