Click to See Complete Forum and Search --> : X11 Forwarding of an Executing Program


trilarian
11-05-2008, 11:15 AM
I don't know why its the tail end of 2008 and it is the first time I've had this question... but I'd like to know of a way (or the switch needed) to remotely connect to a program already running.

I already have X forwarding working fine and can invoke a new instance of any program off of my home server to any computer with an Internet connection. What I would like to do, is forward the instance of the program that is already running and NOT invoke a new instance. Basically this will be to check status of a program's execution or download(s) without reading log files (percent done on a backup to DVD for example).

happybunny
11-06-2008, 12:06 AM
http://www.tightvnc.com/ ?

hlrguy
11-06-2008, 02:42 AM
I don't think even with SSH redirection of the X11 port the program is connected to can be changed once it is running. I agree with happybunny, start a VNC server session on the server, you can then connect/reconnect at will. Course, you need to start the running program inside that VNC session.

hlrguy

trilarian
11-06-2008, 12:54 PM
Thanks - though I was aware of VNC already. The limitation of VNC is twofold. First you have to initiate the program from within the VNC connection (meaning I can't initiate VNC after the fact to check on my desktop as I left it). And the other, is that it sends over an entire session instead of just one program.

Lets say a very simple program like xcalc can be invoked by SSH into the server, have a X server present on the client machine, then xcalc & from the ssh session. This gives you a new instance of the xcalc program on your client machine whilst executing on the server.

What I was hoping for, is that I start xcalc locally and then leave my residence. At some point at work I wish to connect to the xcalc program and only the xcalc program (saves on bandwidth lag). However, the catch is I want to connect to the instance already running. It seems it should be possible since you can already forward an instance of the program itself. I must admit I don't know enough of how the X-Server works to know how or if its possible to play a man in the middle type situation (or daisy chain).

The programs I'd have most use for this type of scenario are ones where I am downloading/uploading files, IRC, any prolonged process (backups, DVD-DL burning, etc.), etc. I would like to try and avoid VNC if possible as my upload speed is limited and often in use, so forwarding my entire desktop instead of just a program window seems to invite more lag.

hlrguy
11-06-2008, 06:48 PM
Well, the root problem, I think using nmap and ssh redirction, you could probably get it to happen. The guru I consult at work for the most difficult things like this is not here today. The problem is, you want and need a "tee" like system. If you could move from one X11 to another display, when you exit, the program exits. Unless you can ssh back into the server and steal it back.

There are ways to speed up VNC. set it to 8 bit, make it 640x480 (it can be any size, not dictated by any screen size), use deferupfate 100ms options, run it over SSH to get compression, etc. It does have the problem you state though. Sorry I couldn't be more help.

hlrguy

hlrguy
11-06-2008, 06:51 PM
Hmmm, well, here's something. See what programs support the -d or -v options. Maybe K3B or whatever will log all information, or ktorrent or whatever.

nohup ktorrent --debug > /tmp/ktorrent.log &

in a terminal. (nohup means you can close the terminal and program stays running). You can then check the log file to see how things are progressing? Indirect kind of deal?

hlrguy

bwkaz
11-07-2008, 12:37 AM
but I'd like to know of a way (or the switch needed) to remotely connect to a program already running. No.

More specifically: Not unless the program does a lot of work to make it possible.

Any GUI program is a client to the X server. The server that it connects to at startup (just before it creates its window(s)) is defined by either the DISPLAY environment variable, or the -display command-line option (if the program supports the latter). Once the program is connected to the X server that you told it to connect to, that X server holds lots of the program's GUI state.

There is therefore no way to move it to another X server, unless you can get the program to destroy all its windows, release all its pixmaps, disconnect, connect to the new server, recreate all its pixmaps, recreate all its windows, and redraw everything.

(Part of the problem is that at the root of the Xlib interface, your Display structure contains a file descriptor along with a bunch of other things. This file descriptor points to a TCP socket that the Xlib functions use to send data to the X server. Since it's TCP, you can't point it at another server process randomly. Also, since the server holds a lot of the client's state, you can't do a fast disconnect/connect cycle; you have to get all that state, then disconnect/reconnect, then send it all to the new server.)

And note that almost all programs allocate a separate X window for each control in their GUI; every button, textbox, etc., all have to be destroyed and recreated...

(Web browsers are one of the few exceptions to this. The reason is that X windows consume resources, and creating a separate window for every button or textbox on a large HTML form page would start to consume lots of resources. But it's still a problem for everyone else.)

trilarian
11-07-2008, 01:53 PM
hirguy: Actually, that is what I'm doing for the time being. Any program that has verbose output can be put into a text file for me to later remote in and read. Nohup wasn't needed though, as in my particular case, the program is started locally. I just wish to monitor it's progress remotely.

bwkaz: Thanks for all the in depth information. I figured in making this post that there would not be an easy answer like "xcalc -h :0" to grab the instance of xcalc on display 0. However, I figured it was worth asking.

In the end, I'll either have to continue reading log files or brave VNC. I just remember WAY back VNC being a bad thing because of no encryption. I could always close that port at the firewall and tunnel through SSH I suppose. The key there, would be to remember to start up the VNC server each time I invoke X.

Thanks for all the input~

JRefL5
11-07-2008, 05:07 PM
If the programs are running from CLI then look into screen (man screen), it allows you to detach a process and reattach to it. in that case you would only need ssh access to a terminal prompt.

trilarian
11-07-2008, 06:01 PM
Thanks for the tip. Unfortunately the programs in question are running attached to a X server. One of the workarounds for one of them was to output to a text file that I picked up via SSH.

I may give VNC another try. The main issue besides what I've already mentioned is me remembering to invoke VNC before I start running programs and leave for the day - or weekend. I recall that using ssh into the box then calling the vncserver started a new X instance instead of attaching to the currently running. I'd rather not keep a vncserver running 24/7 for security purposes (even though I could block the port at the firewall - I don't like the idea that someone could monitor my usage).

hlrguy
11-09-2008, 06:57 PM
As you know, you can encrypt the VNC stream over ssh. They way I do it on my test machines at work, I never actually work in :0. VNC Server starts automatically on boot and I simply do all work, always through :1. It is tricky to set up, but works well. Also, you get pretty good compression over SSH, making it much faster.

What would be ideal is to remote display :0, but VNC starts at :1. If I think up anything else, I'll let you know.

hlrguy

Edit: Just to be clear, you can vncviewer the local server, and working locally, it is lightning fast.

furrycat
11-10-2008, 10:33 AM
It's possible to start a VNC server on an already running display. x11vnc is the tool for that.x11vnc -passwd <serverpassword>You can also try to share out one particular window. You need to find out the window ID. This is easy enough if you already have a display up: simply type xwininfo and click the window in question. If you are already remote you can tryxlsclients -display <display> -a -lwhere the display is as appropriate (perhaps localhost:10 if you are using SSH forwarding for example). Unfortunately you may not be able to find the window if it opens subwindows. Assuming you do find it you can tryx11vnc -passwd <serverpassword> -id <id>orx11vnc -passwd <serverpassword> -sid <id>An alternative is to install No Machine (http://www.nomachine.com/) on your server and start a "floating window" session when you first launch your tool. It will behave the same whether it's local or remote. No Machine offers a free version which is limited to 2 concurrent sessions or you try the FreeNX project.

hlrguy
11-10-2008, 03:31 PM
Of course, if a computing problem exists, there is, no doubt, a solution. Just need to get the expert into the thread. Thanks furrycat, I am going to play with x11vnc now, add that to my resume. :D

hlrguy

trilarian
11-10-2008, 04:19 PM
Of course, if a computing problem exists, there is, no doubt, a solution.

Agree....

furrycat: Thanks a bunch. That is exactly what I was looking for. I went home for lunch and fired up VNC and opened a program. Then from work I SSH into the box and x11vnc with the id option - worked like a charm.

It always makes me happy when I end up being able to do exactly what I set out to do instead of settling for a workaround.:D