https://www.jianshu.com/p/8001a66d37c9
public class ShutdownHookTest {
public static void main(String[] args) throws Exception {
Runtime.getRuntime()
.addShutdownHook(new Thread(() -> System.out.println("ShutdownHookTest")));
while (true) {
Thread.sleep(5000);
}
}
}
2017-09-01 15:38:29
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode):
...
Historical versions of nohup did not affect standard input, but that causes problems in the common scenario where the user logs into a system, types the command:
nohup make &
at the prompt, and then logs out. If standard input is not affected by nohup, the login session may not terminate for quite some time, since standard input remains open until make exits. To avoid this problem, POSIX.1-2008 allows implementations to redirect standard input if it is a terminal. Since the behavior is implementation-defined, portable applications that may run into the problem should redirect standard input themselves. For example, instead of:
nohup make &
an application can invoke:
nohup make </dev/null &
The redirection of stdin for nohup is entirely optional as nohup will usually redirect it to </dev/null if it was a terminal, to avoid the terminal not being able to close when you type exit. You can do your own 0< redirection, to /dev/null or a file, to avoid