PROJET AUTOBLOG


Shaarli - Les discussions de Shaarli

Archivé

Site original : Shaarli - Les discussions de Shaarli du 23/07/2013

⇐ retour index

How to keep processes running after ending ssh session? - Ask Ubuntu

lundi 1 juin 2015 à 23:18
Alex's shaarli 01/06/2015
un process lance dans une session tmux sur une machine distante continuera a tourner meme si la connection ssh est interompue. Il suffit de detacher la session tmux apres avoir lance le job, il est alors possible de clore la connection ssh et la tache continuera a tourner.

Pratique pour lancer des taches longes sur une machine distante.
(Permalink)

Les Liens de Memiks 02/06/2015
tmux est plus sympa que screen oui, mais si on n'a pas besoin de récupérer la main sur la commande (genre un tar, ou un find ou etc...) je rappelle qu'un simple nohup suivi d'un & à la fin de la commande ne demande aucune installation suplémentaire.

donc:

nohup "la commande qui va bien" 2>fichier_erreur.log 1>fichier_sortie.log &

nohup, va ignorer la mort du shell et donc rattacher le processus au père:
https://en.wikipedia.org/wiki/Nohup

le canal 2 est le canal d'erreur.
le cana 1 est le canal de sortie standard
& permet de rentre la main au shell en créant un fork.

Voila.

Sinon pour tmux:
via http://macahute.net/shaarli/?URV-MQ

As screen is not maintained anymore you should look for modern alternatives like tmux.

tmux is superior for many reasons, here are just some examples:

   Windows can be moved between session and even linked to multiple sessions
   Windows can be split horizontally and vertically into panes
   Support for UTF-8 and 256 colour terminals
   Sessions can be controlled from the shell without the need to enter a session

Basic Functionality

To get the same functionality as explained in the post with the most votes you would need to do the following:

   ssh into the remote machine
   start tmux by typing tmux into the shell
   start the process you want inside the started tmux session
   leave/detach the tmux session by typing Ctrl+B and then D

You can now safely logoff from the remote machine, your process will keep running inside tmux. When you come back again and want to check the status of your process you can use tmux attach to attach to your tmux session.

If you want to have multiple session running side-by-side you should name each session using Ctrl-B and $. You can get a list of the currently running sessions using tmux list-sessions.

tmux can do much more advanced things then handle a single window in a single session. For more information have a look in man tmux or http://tmux.sourceforge.net/. A FAQ about the main differences between screen and tmux is available here: http://tmux.git.sourceforge.net/git/gitweb.cgi?p=tmux/tmux;a=blob;f=FAQ
(Permalink)