0

Let's say in a PuTTY connection I start

mysqldump --host host1 --databases db1 db2 db3 | mysql

which creates two processes: mysqldump with PID 5800 and mysql with PID 5801. Is it possible to let the running processes continue execution when I want to close PuTTY and still be able to get back to them later?

I found some answers around here that deal with a single process and how to use reptyr to re-parent it to screen, but my concern is how to deal with my two processes that run in parallel.

kubanczyk
  • 13,502
  • 5
  • 40
  • 55
  • 1
    That question is about one single process, mine is about two processes that use a pipe and that is actually my biggest concern as I don't want to break the communication between the two (yes, I understand it's actually unidirectional). –  Jul 18 '19 at 17:34

2 Answers2

1

Leave your busy session running.

Open another fresh session.

Use tmux so that app will persist even if you close or lose your ssh connection. The tmux is similar to screen, arguably a bit better.

sudo apt install tmux
tmux

Now the crucial step, steal the terminal of the processes.

sudo apt install reptyr
ps uw    # find one of the PIDs to save, any will do
reptyr -T the_PID

I've noticed one side effect of the reptyr -T method. You also catch your old shell along the running apps. If you exit now, you return to original shell of tmux/screen. Use exit again and you're back to your login shell.

kubanczyk
  • 13,502
  • 5
  • 40
  • 55
0

how to deal with two processes that run in parallel?

There is a lot of possible answer, using or not screen, tmux or tools, or running as background tasks, using separated log files...

Running two process separatedly

You could use named fifo:

mkfifo $HOME/mysqlFifo

Then run in two separated terminal console:

mysqldump --host host1 --databases db1 db2 db3 >$HOME/mysqlFifo

and in second window:

mysql <$HOME/mysqlFifo

Then let it run...

I want to close PuTTY and still be able to get back to them later?

screen too

Some preparation:

cat >$HOME/mysqlScreenRc <<eof
screen -t dump mysqldump --host host1 --databases db1 db2 db3 >$HOME/mysqlFifo
screen -t mysql mysql <$HOME/mysqlFifo
eof
mkfifo $HOME/mysqlFifo

then

screen -S mysql -c $HOME/mysqlScreenRc

or

screen -dmS mysql -c $HOME/mysqlScreenRc

to let it run in background...

Then to connect and watch:

screen -r mysql

For ensuring screen stay open afte commands terminated, you could use read command:

cat >$HOME/mysqlScreenRc <<eof
screen -t dump sh -c 'mysqldump --host host1 --databases db1 db2 db3 >$HOME/mysqlFifo;read foo'
screen -t mysql sh -c 'mysql <$HOME/mysqlFifo;read foo'
eof

But you could just run in background with separated logs:

nohup mysqldump --host host1 --databases db1 db2 db3 2>/somepath/mysqldump.err |
    mysql >/somepath/mysql.log 2>/somepath/mysql.err &

So you could close this console, then watch about files in /somepath...