Reputation: 1474
I have a java application which is compiled and packed as Jar file. It contains a while(true) loop inside the application.
My main problem is this, when i run my application in unix server by using
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.
Does nohup process shuts down after a while? Does it have any timeout or any configuration I have to make? And what is the best way to create background process at server?
Upvotes: 1
Views: 1726
Reputation: 123
Nohup won't stop unless the program exits or you interrupt the process (this includes you disconnecting from an ssh shell). To launch the program in the background, add an ampersand (&) after the command:
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.
And one additional possibility -- on some machines, low-priority cpu-hogging programs can get killed automatically. If your while loop isn't ever yielding, this (though unlikely) might be the reason the process is getting shut down.
Upvotes: 0