Frage

Hello I am making a Java program in an Ubuntu Web Server but it is always supposed to be running in an infinite loop, or at least until I stop it. When I run it in the Ubuntu console it won't allow me to keep using the console. To work around this I have been using the "screen" command and detaching the screen. I was wondering if there is a better way of doing this without working with the screen command?

War es hilfreich?

Lösung

Run a program immune to hangups

If you're happy with starting the Java program up manually from the command line, but just want to not have screen running, you can use the "nohup" command to start the Java process in such as way that the Java program will continue running even if you close the console window or log out.

$ nohup java ...
nohup: ignoring input and appending output to `nohup.out'
$

Run a program in the background

If you don't mind the Java program stopping if you close the console window or log out, you can skip using "nohup" and only append a "&" to the end of the command to tell your shell to run the application in the background. You may also want to add " > program.log 2>&1" to the command to avoid having any output from the program show up in the console window while you're using it for other purposes.

$ java ... > program.log 2>&1 &
[2] 3128
$ jobs
[2]+ Running            java ... > program.log 2>&1 &
$

Run a program as a daemon

If you want the Java program to automatically start up every time you reboot the machine, you should look into creating a SYSV init-script, or as you're running on Ubuntu, an Upstart Job definiton.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top