Reputation: 485
I've searched, googled, sat in IRC for a week and even talked to a friend who is devoutly aligned with linux but I haven't yet received a solid answer.
I have written a shell script that runs as soon as I log into my non-root user and runs basically just does "./myprogram &" without quotation. When I exit shh my program times out and I am unable to connect to it until I log back in. How can I keep my program running after I exit SSH of my non-root user?
I am curious if this has to be done on the program level or what? My apologizes if this does not belong here, I am not sure where it goes to be perfectly honest.
Upvotes: 2
Views: 2777
Reputation: 1
You might also want to use the batch (or at
) command, in addition to the other answers (nohup
, screen
, ...). And ssh
has a -f
option which might interest you.
Upvotes: 0
Reputation: 3405
Beside using nohup
, you can run your program in terminal multiplexer like screen
or tmux
. With them, you can reattach to sessions, which is for example quite helpful if you need to run terminal-based interactive programs or long time running scripts over a unstable ssh connections.
boybu
is a nice enhancement of screen
.
Upvotes: 7
Reputation: 7838
There's two signals that can cause your program to die after your ssh
session ends: SIGHUP
and SIGPIPE
.
SIGHUP
will be sent to your program because the parent process (ssh
) has died. You can get around this either by using the program nohup
(i.e. nohup ./myprogram &
) or by using the shell builtin disown
(./myprogram& disown
)
SIGPIPE
will be sent to your program if it tries to write to stdout
or stderr
after the ssh
session has been disconnected. To get around this, redirect them to a file or /dev/null
, i.e. nohup ./myprogram >/dev/null 2>/dev/null &
Upvotes: 2
Reputation: 4074
Try nohup: http://linux.die.net/man/1/nohup
Likely your program receives a SIGHUP signal when you exit your ssh session.
Upvotes: 3