Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Leave bash script running on remote terminal while not logged in?
How do I detach a process from Terminal, entirely?

I'm running a program on a linux server that will take days to complete.

I'm launching it from my workstation from an SSH terminal, as this program is command-line only.

I want to be able to do all of these :

  • launch that program,
  • redirect standard outputs to files,
  • exit my SSH session without making this terminate the process.

I thought about $ ./MyProg.csh -params -foo -bar </dev/null 1>~/out.log 2>~/err.log &

However, the process is terminated the moment I close my SSH session. My workstation is running Windows XP, and I cannot guarantee its uptime over several days, which is required for the processing of my data on the Linux server.

As you may have noted, my program requires to be launched from CSH.

Is it possible to do this ?


share|improve this question

marked as duplicate by slhck, Simon Sheehan, 8088, Sathya Nov 18 '11 at 8:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 8 down vote accepted

you can either user screen or nohup

if you choose screen :

launch screen before you run your service:

$ screen

and then, run your service inside of the screen:

./ > myprog.log ( or anything you want here ).

and then Ctrl+a d

when you came back, just:

$ screen -r

for more information:

about the nohup : just:

nohup ./ > myprog.log &

share|improve this answer
AWESOME! I knew I could manage using screen but I wasn't able to get through it. This is plain awesome, thank you so much! – Benoit Duffez Nov 17 '11 at 16:52
you are welcome :) – bitsMix Nov 17 '11 at 16:54

Make a shell wrapper like this:

exec </dev/null
exec >> ~/out.log
exec 2>> ~/err.log
exec setsid ./MyProg.csh -params -foo -bar

If you need PID file too, then send this shell script to bg and read $! (PID of last bg process). You can do it using subshell with () in the same script like this:

( exec </dev/null
  exec >> ~/out.log
  exec 2>> ~/err.log
  exec setsid ./MyProg.csh -params -foo -bar
) &
kill -0 $! > /dev/null 2>&1 || exit 1
echo $! >
exit 0
share|improve this answer

The connection drops because the shell sends SIGHUP to all children when it exits. If you use bash or zsh, you can use disown and the shell will no longer send SIGHUP and the processes will stay around.

screen and setsid above works, but this answer has the advantage of not having to remember to do screen before you start anything. screen has a lot of power other than this, so you may want to get into a habit of using it.

share|improve this answer
I have to use csh. – Benoit Duffez Nov 19 '11 at 13:47

Not the answer you're looking for? Browse other questions tagged .