简体   繁体   English

Nohup Java进程超时或被杀死

[英]Nohup java process timeout or killed

I have a java application which is compiled and packed as Jar file. 我有一个Java应用程序,该应用程序已编译并打包为Jar文件。 It contains a while(true) loop inside the application. 它在应用程序内部包含一个while(true)循环。

My main problem is this, when i run my application in unix server by using 我的主要问题是,当我使用以下命令在UNIX服务器上运行应用程序时

nohup java -jar processName.jar > log.txt

it starts well. 它开始很好。 After a while(i do not know the reason, and log file does not exist any exception) it seems to shut down. 一段时间后(我不知道原因,并且日志文件不存在任何异常),它似乎已关闭。 I can see the process by ps -ef but log file and output file does not change at all. 我可以通过ps -ef看到该过程,但是日志文件和输出文件完全不变。


Does nohup process shuts down after a while? 一段时间后,nohup进程是否关闭? Does it have any timeout or any configuration I have to make? 它是否有超时或我必须进行的任何配置? And what is the best way to create background process at server? 在服务器上创建后台进程的最佳方法是什么?

Nohup won't stop unless the program exits or you interrupt the process (this includes you disconnecting from an ssh shell). 除非程序退出或您中断进程(包括从ssh shell断开连接),否则Nohup不会停止。 To launch the program in the background, add an ampersand (&) after the command: nohup java -jar processName.jar > log.txt & 要在后台启动该程序,请在命令后添加一个&符号: nohup java -jar processName.jar > log.txt &

Screen can also be useful if you want to easily kill it later. 如果您以后想轻松杀死它,屏幕也可能很有用。

If it's still stopping when run in the background, something in the Java code is silently exiting, so investigate there. 如果在后台运行时它仍在停止,则Java代码中的某些内容会静默退出,因此请在那里进行调查。

And one additional possibility -- on some machines, low-priority cpu-hogging programs can get killed automatically. 还有另一种可能性-在某些计算机上,低优先级的CPU占用程序会自动被杀死。 If your while loop isn't ever yielding, this (though unlikely) might be the reason the process is getting shut down. 如果您的while循环从未成功,这(虽然不太可能)可能是进程关闭的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM