linux – How to keep a process open when closing the SSH session?


It turns out that I have a process that I would like to keep open indefinitely. If I start the process from SSH, when I exit the SSH session the process also closes.

I want to know how you can leave that process running even if you exit the SSH session.



  1. tmux and screen are not primarily for what you want, they are a multiplexer and a terminal emulator respectively. That they allow you to keep a process running on a remote server is not their main feature. Using them just for that is underusing them and leaving too many programs running on your remote server.

  2. Unlike what @patapalo said, the '&' character does not keep a process open after logging out. What it does is it passes it to the background allowing the shell from which it was run to continue working. If you close the ssh connection this process stops.

What you need is the nohup program that is designed for that.

The way to run nohup is as follows:

nohup ./programa &

What nohup does is make a program ignore the SIGHUP signal. When one runs a program and then exits the terminal, even though it has been run in the background with ./programa & , the program receives a SIGHUP signal which suspends the execution of the program. On the other hand, with nohup you can keep running the program despite closing the ssh session or sending a signal like kill -1 pid_del_programa .

To kill it, you only have to kill the process associated with the program, either with kill (of course, as long as you don't send signal 1 or SIGHUP ) or with a process viewer, etc.

Scroll to Top