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?
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.
nohup
for this task is a workaround to a 100% non-issue... i have no idea how/why nohup
became the commonplace "solution", nor do i know of a technical limitation to the method outlined above. a double-fork is clean, fast (avoids a fork, should it matter), retains the use of SIGHUP proper, and works on any shell since ~30yrs. while i can't cite details off-hand, nohup
bit me a few times when unknowingly ran applications under it that made legitimate use of SIGHUP (of which there are many). –
Inexpert The modern and easy to use approach that allows managing multiple processes and has a nice terminal UI is hapless utility.
Install with pip install hapless
(or python3 -m pip install hapless
) and just run
$ hap run my-command # e.g. hap run python my_long_running_script.py
$ hap status # check all the launched processes
See docs for more info.
A command launched enclosed in parenthesis
(command &)
will survive the death of the originating shell.
SIGHUP
signal, AFAICT –
Roxie screen -ls
List sessionsscreen -S session_name
Starting New Session with nameI've used nohup
and &
, but personally, I find the screen
command to be much better.
Linux Screen is a Terminal multiplexer that lets users create multiple virtual shell sessions in their system. It saves the current process in Terminal, keeping it running even after the user disconnects from the server.
from https://www.hostinger.in/tutorials/how-to-install-and-use-linux-screen
© 2022 - 2024 — McMap. All rights reserved.
nohup
? – Westering