I have a java program (text-based no GUI) that I have written and compiled and uploaded to a server.
I run it with java -cp myjar.jar mypackage.MyClass
which starts it running processing a datafile with 20,000,000+ entries in it and printing output to System.out
. I have calculated that it will take a very long time to process the data and I didn't want to have my laptop open for the 10 days of number crunching...
When I log out of my shell however, the process stops.
How can I execute the command and log out without it stopping? What is that even called?
I am using an Amazon Ubuntu EC2 server. I log in using a certificate from Mac OSX with terminal. The server seems to be using a bash shell.
Hope someone can help me out! Jason.
You can use nohup
nohup java -cp myjar.jar mypackage.MyClass > yourLogFile.log &
Consider using screen instead of nohup . It allows you to create a virtual terminal that persists even after you logout/disconnect. When you reconnect to the server, you can immediately jump into the screen
session you last had open.
Typical workflow on the server:
screen
(you may need to press space to leave intro page) ctrl a+d
to leave screen (make sure to hold ctrl down) To re-enter screen just use screen -r
, and you will see the previous terminal and any running programs as you left it.
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.