Thread: Why do I need & after xclock to get it to display over ssh?

  1. #1
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329

    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.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Last edited by matsp; 03-01-2008 at 03:53 AM.
    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.

  3. #3
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    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?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  5. #5
    Banned
    Join Date
    May 2007
    Location
    Berkeley, CA
    Posts
    329
    Then why would something like

    xclock &

    work?

    Why does the'&' make a difference in this case?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

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