49

I am using putty to interact with Linux server. I have started a process using putty. The process is running and will take 5-6 hours. I want that process to keep running after I close the putty session. How can I keep that process alive after closing the putty session? I do not want to keep the computer ON all the time. Is there any way to do this?.

11 Answers11

37
^Z
bg %1
disown -h %1

The '-h' makes the process immune to SIGHUP when the session completes.

Tom Anderson
  • 1,833
35

I use screen for that kind of stuff. Actually sometimes I just leave it on quite a while so I can get back to what I was doing.

Update 2021: I also started using tmux lately.

mtmk
  • 611
23

Use the nohup command. Just prefix it to your command and it will daemonise them so that they won't stop when you log off/terminate your shell session. The standard output will by default be in a file called nohup.out. Check the manual page for nohup(1) for more information.

6

Start process with nohup "processname" &. You can also detach it with screen or tmux.

Excellll
  • 12,847
Damir
  • 151
6

The above solutions are quite well described, however, none of them worked for me UNTIL I also edited PuTTY configuration to :

Enable TCP keepalives (SO_KEEPALIVE option)

I hadn't seen this anywhere else, and just found it by trial and error.

2

if the process is a for nodejs, and it may be your intention since you originally posted this on stackoverflow. I was originally searching for this question myself. I found pm2 and it is amazing. The other answers may help for general putty but if it is node specific this is by far the best answer, as there is built in monitoring and the setup is simply a

$ npm install pm2 -g
$ cd yourappdirectory

"PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

Starting an application in production mode is as easy as:"

$ pm2 start yourappname.js

"using the save and then freeze command you enable the processes to autostart on reboot"

$ pm2 save
$ pm2 freeze

for monitoring its

$ pm2 monit

and restarts

$ pm2 restart yourappname

also for direct logging information

$ pm2 logs

I now can easily run two putty windows instead of using my digialocean browser window (which I couldnt scroll up on); For more info see the main github

https://github.com/Unitech/pm2

its amazing.

1

You can use & after the link.

Example:

[localhost ~ ]# wget http://www.link.com/download/download.zip &
Excellll
  • 12,847
codemania
  • 121
1

Ctrl+z Send the current process to the background.

Also, you may add & at the end of your command to run in in background

0

How to keep weblogic running after closing putty window:

Simple Steps: after the login through putty follow the below steps:

  1. Go to the directory on the server where the startWebLogic.sh command is located.
  2. Type command screen and press Enter (a new screen will open).
  3. In the new screen type your run command ./startWebLogic.sh.
  4. Press Ctrl+a then press d (without holding Ctrl); you will return back to the previous screen.
  5. When you want to return to your server log screen, type command screen -r.
Toby Speight
  • 5,213
Akbar
  • 1
0

From https://gist.github.com/davydany/d33f4b5e19eab6b805b045b91d3cf858

How to Run a Process in the Background with TMUX

There are times when you need to log off your Linux Desktop, and you want a process to run in the background. TMUX manages this very well.

For this example, let's suppose you're running a long running task like running rspecs on your project and it is 5pm, and you need to go home.

Run Your Process

1. First launch TMUX

$ tmux

2. Run your long running process

$ bundle exec rspec spec

3. Detach from TMUX

Simply press [CTRL]+[b], then [d]. This will detach your session from TMUX

4. Log off

Now you can simply log off

Return to your session

When you return back to your desktop, open a terminal and simply run:

$ tmux attach

OR

$ tmux a

This will attach to your detached TMUX session.

Other Helpful Hints:

  • Create a new tab: [CTRL]+[b], [c]
  • Switch to tab number: [CTRL]+[b], <number>
  • Enable Scrolling up / Page up: [CTRL]+[b], [
zwcloud
  • 290
0

If you want the program that is contained in the process to always or frequently run in the background, you can code it to separate from the controlling terminal (make such behaviour controllable via an option flag) and run in the background.

That's a long term solution, of course, not for the currently running process.

mpez0
  • 2,842