what happens to X apps over SSH when the server goes down?

Asked by Bogdan Butnaru

Hi! I've recently started toying with running apps on different computers, using SSH X-forwarding.

For instance, I'm running Amarok on another computer (which happens to have a big drive and speakers, but no display) with the X server on my current computer (no drive space, but nice display).

It runs OK, but I've been having a few surprises. First, when I rebooted the computer with the display, I've been surprised to see that Amarok kept going on the other machine, the music kept playing until the play-list finished.

How can it still run when not only it's server isn't there anymore, but even the session it's running on is gone? (I assume it is, since the SSH connection went down too on reboot.)

I've had another surprise, when I checked the processes on the no-display machine, there were a couple dozen Amarok processes running, probably from my earlier experimentations.

So, my question is two-fold:
(1) How can I tell if I still have apps running that are started from a dead connection?
(2) Can I bring such apps back to the remote display when I reconnect? For that matter, can I bring an entire running X session over to another X server, or at least parts of it?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Georges
Solved:
Last query:
Last reply:
Revision history for this message
jz (jz+) said :
#1

1. I believe you should have a message similar to "Connection to remote host terminated" or something close to that if the ssh session ends because a machine went off line etc...
2. You would have to start a new session with X forwarding as well as restart whatever app you were in the process of using.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#2

1) Where would these messages appear? And even if they do, it doesn't mean there are apps still running.

2) Yes, it's quite obvious that I can start a new session and restart the programs. I'm curious if I can start a new session and attach _already running_ programs to it.

Revision history for this message
Jeff Greene (jeffgreene) said :
#3

If you want to find out, start a ssh session and run something like gedit. Terminate the session. Then on the computer where gedit was opened on, go to the terminal and type:
ps aux | grep gedit | grep -v grep

If it shows something running, then that means gedit is still running.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#4

Sorry, I misspoke. I know how to tell if there is an instance of some app running there. In this case, Amarok remains running if I kill the ssh connection that opened it, but gedit closes. I don't know why. But the test you gave doesn't work, because the app may be running locally, or started by another user.

What I need is to explicitly find out if there is an X application running that doesn't have access anymore to the X server that it was started on. (Your test doesn't show that, because the running apps may be started with other, still existing, X servers.)

I also need to know if I can reattach such an app to another X server.

Revision history for this message
Alan Pope 🍺🐧🐱 🦄 (popey) said :
#5

Amarok is one of those special programs that has a tray icon, so even if you click "close", it remains open. I dont know if you can turn that feature off, but you might want to look for an option to do that. I don't use amarok but a friend tells me there is such a preference but may or may not work, you might want to try it.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#6

I might try that. But still, I'm not sure how it happens, but the tray icon does appear on my computer, i.e. the same computer where the window shows up. Which (1) is useful, because I can use it the same way I use it when I run Amarok locally and (2) it means that the connection to the panel is also done through SSH. So it could probably detect that is has no "user" anymore. Anyway, even an app that goes on the panel should realize that its X server is no longer available...

But that's a special case, maybe I could file a feature-request for Amarok. But this support request is more general.

(1) Can I detect an X application that doesn't have a connection to its X server anymore.
(2) Can I move an already-running X application to a different X server?

Revision history for this message
Best Georges (georgeskesseler) said :
#7

(1) To detect if an X application still has a connection is a bit tricky. One could probably find out with lsof and netstat. As I have never tried that, I won't give an answer now if that is going to work or not.

(2) It is impossible to move an X application to a different server, be it one running on an existing server or on a dead server.
There is a workaround, but you have to know in advance if you will have to move the application. You have to send it to an intermediate X server. This can be xmove or also vncserver to name a few.

Revision history for this message
Bogdan Butnaru (bogdanb) said :
#8

Thanks! It seems that xmove does exactly what I need for moving apps between displays. And I don't believe I'll need (1) anymore if I use xmove, because all remote apps will be started on the xmove server anyway.

Revision history for this message
Rampage (jilan-shah) said :
#9

I have been looking for a tool to do something similar to what you did Bogdan. And I did find xmove to do exactly whats needed from the description.

What were your steps for redirecting the graphical output to different X Servers?

Also its quite an old application (xmove), is there something newer that is under active development?

Thanks