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 ?
在Linux中,可以使用两个不同的信号暂停进程,SIGSTOP和SIGTSTP。这两个都不是由HotSpot虚拟机处理的,SIGSTOP因为不能被捕获,SIGTSTP因为没有被HotSpot处理。我想知道发送这两个信号是否安全,或者万一不安全,JVM的哪个部分会受到影响(例如垃圾收集器)。注意,我并不关心运行在JVM上的程序可能存在的问题,我特别关心JVM的内部结构。向JVM发送停止/TSTP安全吗?
1 个解决方案
#1
3
SIGSTOP
and SIGTSTP
are not included in HotSpot JVM's signal handling doesn't mean HotSpot JVM doesn't support them.
SIGSTOP和SIGTSTP不包含在HotSpot JVM的信号处理中,并不意味着HotSpot JVM不支持它们。
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).
这只意味着对于这两个信号没有特殊的处理。一些信号(SIGSEGV、SIGTERM等)是HotSpot JVM专门处理的,以实现某些特性(隐式空检、关机挂钩等)。
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.
那些没有特别处理的,它们会表现出默认的方式。因此,当HotSpot收到SIGSTOP和SIGTSTP时,会表现为默认方式,即暂停和终端暂停。
In fact, SIGSTOP
cannot be ignored. From signal(7)'s man page:
事实上,SIGSTOP是不可忽视的。从信号(7)手册页:
The signals
SIGKILL
andSIGSTOP
cannot be caught, blocked, or ignored.信号SIGKILL和SIGSTOP不能被捕获、阻塞或忽略。
We can demonstrate this by a simple C program:
我们可以通过一个简单的C程序来演示:
#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.
没有信号处理SIGSTOP或SIGTSTP,但仍然可以将它们发送到这个简单的程序中,它们将会正确运行。
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.
通过按Ctrl+Z将发送一个SIGTSTP信号,通过run kill -19 pid将发送一个SIGSTOP信号。演示程序会暂停。
In both cases, running a kill -18 pid
will send SIGCONT
signal and bring our demo program back to execution.
在这两种情况下,运行kill -18 pid将发送SIGCONT信号,并将我们的演示程序带回执行。
#1
3
SIGSTOP
and SIGTSTP
are not included in HotSpot JVM's signal handling doesn't mean HotSpot JVM doesn't support them.
SIGSTOP和SIGTSTP不包含在HotSpot JVM的信号处理中,并不意味着HotSpot JVM不支持它们。
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).
这只意味着对于这两个信号没有特殊的处理。一些信号(SIGSEGV、SIGTERM等)是HotSpot JVM专门处理的,以实现某些特性(隐式空检、关机挂钩等)。
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.
那些没有特别处理的,它们会表现出默认的方式。因此,当HotSpot收到SIGSTOP和SIGTSTP时,会表现为默认方式,即暂停和终端暂停。
In fact, SIGSTOP
cannot be ignored. From signal(7)'s man page:
事实上,SIGSTOP是不可忽视的。从信号(7)手册页:
The signals
SIGKILL
andSIGSTOP
cannot be caught, blocked, or ignored.信号SIGKILL和SIGSTOP不能被捕获、阻塞或忽略。
We can demonstrate this by a simple C program:
我们可以通过一个简单的C程序来演示:
#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.
没有信号处理SIGSTOP或SIGTSTP,但仍然可以将它们发送到这个简单的程序中,它们将会正确运行。
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.
通过按Ctrl+Z将发送一个SIGTSTP信号,通过run kill -19 pid将发送一个SIGSTOP信号。演示程序会暂停。
In both cases, running a kill -18 pid
will send SIGCONT
signal and bring our demo program back to execution.
在这两种情况下,运行kill -18 pid将发送SIGCONT信号,并将我们的演示程序带回执行。