I want to run a process in a remote linux server and keep that process alive after close the putty terminal,
what is the correct command?
You have two options:
nohup some-command &
, which will run the command in the background, detach it from the console, and redirect its output into nohup.out
. It will swallow SIGHUPs that are sent to the process. (When you close the terminal or log out, SIGHUP is sent to all processes that were started by the login shell, and the default action the kernel will take is to kill the process off. This is why appending &
to put the process in the background is not enough for it to survive a logout.)don't use that nohup junk, i hate seeing that on servers; screen is a wasting pile of bits and rot -- use tmux.
if you want to background a process, double fork like every other daemon since the beginning of time:
# ((exec sleep 30)&)
# grep PPid /proc/`pgrep sleep`/status
PPid: 1
# jobs
# disown
bash: disown: current: no such job
enjoy.
A command launched enclosed in parenthesis
(command &)
will survive the death of the originating shell.