Monday, September 26, 2016

make a process continue to run after disconnect from ssh using tmux

1- install tmux
$ sudo apt-get install tmux

2- small script to print "." every 2 second, name it as
import time
i = 0
while i <1:
 print "."

3- run the script in tmux and make it run in background
$ chmod 755
$ tmux
$ ./

press (ctrl+z) to stop the process

- list jobs list
$ jobs
[1]+  Stopped                 ./

we see it is on number 1 of jobs list

- convert it to rub background

$ bg 1

4- detach the session in tmux
press ctrl + b  then d

5- now you can safely exit the ssh session, the the process still running

6- when you ssh back to the host, you can attach to previose tmux session and you will see the script is still running
$ tmux attach

No comments:

Post a Comment