简体   繁体   English

在Linux中将Java进程作为后台进程运行

[英]Run java process as background process in linux

I am running my project as jar using java -jar command in Linux machine. 我在Linux机器上使用java -jar命令将项目作为jar运行。 As soon as this program run , It produces logs in another directory. 该程序运行后,它将在另一个目录中生成日志。 Running my program this way requires me to keep the shell open. 以这种方式运行程序需要我保持外壳打开。 Now If I have to see the logs , I can't do that in the same shell. 现在,如果我必须查看日志,则无法在同一外壳中执行该操作。 I am forced to do that by either doing the duplicate session or new session. 我被迫通过重复会话或新会话来做到这一点。 Is there any way I can run the jar as background process and see the logs in the same shell ? 有什么办法可以将jar作为后台进程运行,并在同一shell中查看日志?

If you don't care about it staying alive, something as simple as nohup java -jar myjar.jar & should work. 如果您不关心它的存在,那么像nohup java -jar myjar.jar &这样简单的事情就应该起作用。 If you need it to be automatically restarted if it crashes or start automatically at boot, you'll want to look into something like systemd or monit. 如果您需要它在崩溃时自动重新启动或在启动时自动启动,则需要研究诸如systemd或monit之类的东西。

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

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