C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-01-2008, 12:01 AM   #1
Registered User
 
Join Date: May 2007
Location: Berkeley, CA
Posts: 140
Why do I need & after xclock to get it to display over ssh?

I have a Linux Machine in my apartment with x11 fowarding. It is
connected to the internet via dialup modem. I access X on Linux
Machine from my Laptop at work via SSH. Now when invoke xclock over
ssh, I have to type

clock &


in order to get the graphical clock to appear on my laptop.


How I have to type & after xclock? I thought that once xclock was
placed in the background, the shell would stop the xclock job when it
tried to read from the standard input. However it doesn't.
Overworked_PhD is offline   Reply With Quote
Old 03-01-2008, 03:45 AM   #2
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Edit: Misunderstood the question.

Any[1] "X" application started without a "&" at the end will run connected to the current task. Essentially what happens is:
Code:
    fork();
    if (!pid) {  // child process
       exec(applicaton);
    }
    else
    {
       if (!background)   // Did it have a "&" at the end, if not do this:
         wait(pid);
    }
So, whilst the xclock creates a new window, if you don't say to the shell to run in the background, the shell still waits for the process to finish.

[1] Of course, it's entirely possible for the application to actually disconnect itself from the shell that started it - this is what daemon applications do.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.

Last edited by matsp; 03-01-2008 at 03:53 AM.
matsp is offline   Reply With Quote
Old 03-01-2008, 11:58 AM   #3
Registered User
 
Join Date: May 2007
Location: Berkeley, CA
Posts: 140
Here is what I don't understand. When I'm connected to a remote
desktop running Linux over ssh and try to execute xclock locally via
the laptop, I get the following

[cdalten@localhost~]$ xclock
Error: Can't open display:


How come the shell wouldn't just do


[cdalten@localhost~]$ xclock


And then display xclock?
Overworked_PhD is offline   Reply With Quote
Old 03-01-2008, 12:44 PM   #4
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
You need to define the display as "machine:0" where machine is your machines name. (Or you could perhaps use "localhost:0" - but that won't work if you are using ssh to connect to another machine, as that would use the display on the machine you are connecting to.

Actually, your machine names itself "localhost", which means that you haven't set a hostname. You could use the IP-address of the machine, but it would probably be better to set up the hostname. How you do that depends a bit on the distro you are using, but generally there is a GUI tool for configuring the system settings, where one of the settings is what the machine is called.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Old 03-01-2008, 03:39 PM   #5
Registered User
 
Join Date: May 2007
Location: Berkeley, CA
Posts: 140
Then why would something like

xclock &

work?

Why does the'&' make a difference in this case?
Overworked_PhD is offline   Reply With Quote
Old 03-01-2008, 06:08 PM   #6
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
Shouldn't make any difference at all.

--
Mats
__________________
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
display character size...(quite urgent..) karthi C Programming 10 07-11-2007 09:42 PM
new problem with class jrb47 C++ Programming 0 12-01-2006 08:39 AM
Help needed Please jereland C Programming 9 03-18-2004 05:30 AM
Tab Controls - API -KEN- Windows Programming 7 06-02-2002 09:44 AM
Speeding Up Display Time in CEditView :: MFC kuphryn Windows Programming 0 04-22-2002 07:24 PM


All times are GMT -6. The time now is 07:53 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22