Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I'm logged into a remote Linux machine, I know I can suspend a process (cntr-z) and move it to the background (bg 1) but if I disconnect from the machine, the process stops.

Is there a way I can leave it in the background and have it there when I log back in? This is a very long running process.

On Unbuntu, logged in via SSH.

share|improve this question
add comment

2 Answers

This is because your program need terminal to run, you can use GNU Screen to create a virtual terminal so that the program will continue to run even after you disconnect.
just run screen your_program_name, you can close screen with crtl-a-d then reopen it later with screen -rx

share|improve this answer
    
Wish I could accept your answer but I posted w/o logging in and now can't actually claim the question. =x But thank you, works perfectly. –  Erik Jun 27 '10 at 16:39
add comment

Less flexible than screen are nohup and disown.

nohup is a program, and you have to start the long running jub with it like this:

$ nohup longjob --options-for-longjob

it will cause your long job to run in the background and not attached to any terminal (which means that you won't get any output from it on the screen and won't be able to direct input to it from the keyboard)

disown is a bash builtin that can disconnect a long running job after you've started it. My bash man page says

disown [-ar] [-h] [jobspec ...]
Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a job- spec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job.

share|improve this answer
add comment

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.