[Linux] Best way to nohup a long running session, tmux

You are here:
  • Main
  • Linux
  • [Linux] Best way to nohup a long running session, tmux
< All Topics

Hello everybody,

how often do you need to run a long running process that has some types of commands with which you have to interact? For example, recently I have tried Worldserver, a software that is a console type process that has to be running in order to allow other people to connect.

This is how I have discovered tmux!

What is tmux

From Wikipedia: “tmux is an open-source terminal multiplexer for Unix-like operating systems. It allows multiple terminal sessions to be accessed simultaneously in a single window. It is useful for running more than one command-line program at the same time. It can also be used to detach processes from their controlling terminals, allowing remote sessions to remain active without being visible.”

Essentially, it allows to create sessions that can be detached and reattached when necessary.

Let’s try it!

Testing environment:

  • Ubuntu 20.04.1 LTS

How to install and use it

It’s very simple to install tmux:

# apt-get install tmux

After this, you can start using it.

To create a new session, you just need to type:

$ tmux

As you can see, it enters in the new session and then you can exit in two ways:

  • by hitting ctrl-d you close the tmux session
  • by hitting ctrl-b d your tmux session remains running

In this second case, you can launch the previous worldserver command and detach the session:

Then you can attach to it in a very simple way:

$ tmux list-sessions #in this way you get all runing tmux sessions, is the first number
$ tmux attach-session -t ${id}

In this manner, you return to the previous terminal and you can write commands, check the output, etc…

That’s it, I think that it is really helpful when you need to launch a very long command that eventually needs some types of prompts.



Table of Contents