简体   繁体   中英

how to keep nohup from killing java process that waits for stdin linux

I have a java program that is executed on command line (Bash Linux). Once executed the program continues to run, reading stdin until the user inputs 'quit'.

Sometimes I would like to nohup the program so it continues to run even if my remote connection is closed. The problem is that when I attempt to nohup the program as demonstrated below it seems that its prompt for stdin kills nohup and terminates the program.

Example: $ nohup java -jar myApp.jar

I have tried redirecting the program's output to 2>/dev/null per other suggestions as well as running it in the background using & . Neither prevents nohup from being killed.

I cannot use disown because once I run the program I lose the command prompt to the program.

To get your program running in the background, run tmux :

tmux

This will open up a tmux shell, where you can run your program:

java -jar myApp.jar

Then to detach from the tmux session, type ctrl-b then d . Your program will continue to run in the background.

To reattach to your program's shell at a later time (to kill it or view its output), run tmux attach .

Although tmux solved my problem, I kept poking around and playing with disown until I got it to work. I was able to keep the java process running after logoff by piping it a super-long sleep command (suggested in this thread ), running it in the background, and then running disown . Like this:

$ sleep 999999999 | java -jar myApp.jar&

$ disown

So, I'm going to stick with tmux , but I just thought I'd share this as it worked as well for my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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