7

I am running long program on server, which is basically Jar file of java program. I want to keep this program running even if SSH terminal is closed, how I can keep this program running on server?

shgnInc
  • 728
  • 7
  • 13

4 Answers4

22

Two different ways:

  1. Use nohup - by starting the program with nohup /path/to/program &, nohup keep the program running and any output will be redirected to the file nohup.out in the current directory
  2. Use screen or tmux if either of them is installed on the server. They are a way to keep one or more shells going so that you can re-attach to them the next time you login - it's a much more powerful utility than nohup. man screen or man tmux for more information.
Jenny D
  • 13,172
2

Here's how to keep a process running that you've already started without using nohup.

Suppose you started decompressing a large archive and now you want to go home.

$ tar -xzf bigfile.tar.gz

Press ctrl-z to send the processs to the background. You can type "jobs" and press enter and see the job number for your process, probably it's 1.

Then do:

$ disown %1
1

Either screen or tmux will both work.

See for instance http://www.jeffstory.org/wordpress/?p=132 for a quick tutorial on how to use it.

0

While I've never used Apache Daemon, it may do what you want. It will run your Java program as a daemon, as a process in the background.

I'd then use htop to monitor this process, and shut it off if it takes up too many resources.

You will need to install htop apt-get:

sudo apt-get install htop

Then run via

htop

When you see your process, you can kill it by selecting it in the list (via the arrow keys) and then kill it by pressing

f9, k 
Starkers
  • 111