Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?.

share|improve this question

migrated from stackoverflow.com Jan 16 '10 at 19:04

5 Answers

up vote 20 down vote accepted

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.

share|improve this answer
The process is running now ,is it work for that process?I am asking because the process is on the middle and i do not want to restart it now – prakash.panjwani Jan 16 '10 at 15:18
+1 for mentioning my undisputed favourite command line tool. It's a gem in situations like this. – Noufal Ibrahim Jan 16 '10 at 15:41
@Noufal, totally! @prakash, you need to run screen before you can start any processes – Maxwell Troy Milton King Jan 16 '10 at 15:48
If you want to connect to several machines it can even be a nice idea to run several screens inside the first screen so you just have to connect to one screen to get access to all your running remotes. – Zitrax Jan 16 '10 at 17:26
^Z
bg %1
disown -h %1

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

share|improve this answer
Note that there's no way to 'reown' or 'adopt' the process - once you've done this, you can't ever bring it back to the foreground. If the process is a batch job working to produce some files, though, that shouldn't matter. – Tom Anderson Jan 16 '10 at 15:34

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.

share|improve this answer
the process is running ,is it work for that process?I am asking because the process is on the middle and i do not want to restart it now? – prakash.panjwani Jan 16 '10 at 15:16
Too late...at least, for normal operations. It wouldn't be altogether surprising to find that if you attach a debugger to the process, and then tweaked it with an appropriate set of system calls, then perhaps you could put it in the background. But it is not what could be recommended - I wouldn't bother, for example, and I have at least some idea of what might be involved. You have two choices now...either stay connected until it finishes, or stop the current process, and restart a new one using nohup. – Jonathan Leffler Jan 16 '10 at 15:19
1  
If you're using bash (and I think zsh), you can use Tom Anderson's solution and disown the process so that it continues to run even when you disconnect. – Noufal Ibrahim Jan 16 '10 at 15:40
Yup - disown looks to be the way to go for an already running job. It's doable because the shell that started the job can manipulate the properties needed. – Jonathan Leffler Jan 16 '10 at 15:56

Ctrl+z Send the current process to the background.

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

share|improve this answer
3  
Normally, control-z puts the process into a state of suspended animation; the bg command puts it into the background. However, that also keeps the process attached to the terminal, whereas nohup detaches it from the terminal and therefore allows putty to disconnect and the process to survive the disconnection. – Jonathan Leffler Jan 16 '10 at 15:15

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.