3

Here is the scenario.

The distribution is Raspbian. I started a program in a SSH session which has continuous output on the screen. Then I suspended it and disown it to exit the session in order to close my laptop and go to sleep.

When I started a new SSH session later I can see the process is still there so I want to bring it back to the front end to see its status and progress.

Can anyone help me on this? I've googled a lot and tried approaches like bg/jobs/fg, screen/tmux (I didn't use them before issue command). None of them work.

I tried reptyr with -T option as the target process has children. It failed:

pi@raspberrypi:~ $ sudo reptyr 1583 -T
[-] Child is not connected to a pseudo-TTY. Unable to steal TTY.
Unable to attach to pid 1583: Invalid argument
2
  • @KamilMaciorowski I will try reptyr and update here later.
    – Leo Chiu
    May 23, 2018 at 5:27
  • Tried reptyr with T option as the target process has children. Failed with prompting pi@raspberrypi:~ $ sudo reptyr 1583 -T [-] Child is not connected to a pseudo-TTY. Unable to steal TTY. Unable to attach to pid 1583: Invalid argument
    – Leo Chiu
    May 23, 2018 at 10:32

1 Answer 1

-1

You will need to run screen first. This will allow you to detach the entire session and be able to bring it up again. If you don't have screen installed, you can install it by running:

sudo apt-get install screen

Once installed, first run screen. This will open a new shell in pseudo-tty. After you start the program, press Ctrl-A D to detach the session from screen. You can now safely log off and the program will continue to run.

To resume, SSH back in and run screen -r. You will be right where you left off and can see the current output.

Another option is to run screen, but run the program like this:

mypgm > output.log 2>&1 &

This will run the program in the background, redirecting all output and errors to output.log.

You can then view the progress by running tail -f output.log

Press Ctrl-C to exit out of the tail -f command.

2
  • The screen solution needs foreseeing in advance but my scenario is adhoc to keep the program running while the session needs to be ended. Moreover, the program is always running and I need to view the output as well even I save the process by disown. No luck. But thanks anyway.
    – Leo Chiu
    May 23, 2018 at 3:54
  • @LeoChiu I use tmux (an alternative to screen) every time I log in, not because I foresee in advance but because it's so convenient. I don't have to worry about multiple sessions, putting in background, disconnections etc. May 23, 2018 at 4:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .