Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


Search this Thread
Old 11-26-2011, 01:35 PM   #1
Registered: Oct 2011
Posts: 34

Rep: Reputation: Disabled
Spawning xterm from Linux service: xterm: DISPLAY is not set


Newbie question here...

I'm trying to create a simple Linux service that:

1. Spawns xterm
2. Within this newly spawned xterm, echoes a message.

I seem to get DISPLAY type errors when the service is run(xterm: DISPLAY is not set)... I tried to set the $DISPLAY to localhost:0, localhost:0.0, etc.. and well as "xterm -display localhost:0 ...." and still have difficulties.

Regardless, here's the code from "/etc/init.d/":

#! /bin/sh -e
# upstart-job

set -e

# Some things that run always

echo "Now going to echo display"


xterm -e /testing/

# Carry out specific functions when asked to by the system
case "$1" in
echo "Starting script "
echo "Stopping script"
echo "Usage: /etc/init.d/ {start|stop}"
exit 1

exit 0

and the script "/testing/":

#! /bin/sh -e
echo "************** THIS IS A TEST *************"

root@bill-ThinkPad-T500:/etc/init.d# update-rc.d defaults
update-rc.d: warning: /etc/init.d/ missing LSB information
update-rc.d: see <>
Adding system startup for /etc/init.d/ ...
/etc/rc0.d/ -> ../init.d/
/etc/rc1.d/ -> ../init.d/
/etc/rc6.d/ -> ../init.d/
/etc/rc2.d/ -> ../init.d/
/etc/rc3.d/ -> ../init.d/
/etc/rc4.d/ -> ../init.d/
/etc/rc5.d/ -> ../init.d/

and then to to start the service I get the display message. Note you can see echo $DISPLAY shows nothing which is a big clue, but when I try to manually set it to localhost:0.0 before calling xterm is doesn't help. What should I do?

root@bill-ThinkPad-T500:/etc/init.d# service start
Now going to echo display

Warning: This program is an suid-root program or is being run by the root user.
The full text of the error or warning message cannot be safely formatted
in this environment. You may get a more descriptive message by running the
program as a non-root user or by removing the suid bit on the executable.
xterm Xt error: Can't open display: %s
xterm: DISPLAY is not set

or trying not as root:

bill@bill-ThinkPad-T500:/etc/rcS.d$ service start
Now going to echo display

xterm Xt error: Can't open display:
xterm: DISPLAY is not set

Thanks for any help...

- Bill
Old 11-26-2011, 05:29 PM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
The problem is because at boot-time, there is no X server available. You can't run an xterm without one. Why do you want to run your service in an xterm? The only time I've ever needed to do this was when I wanted to start a perpetually running program that has an interactive console. I accomplished that using screen. You can start a screen session in a detached mode, and then, from your script, use screen's stuff command to stuff commandlines into the session. The commandlines that you stuff there would be contrived to start your program. You can later (after booting completes) attach to the screen session to witness your program's progress and potentially interact with it, if that's what it does. There are a lot more details to this method, but that is the general approach.
If you really need it to run in an xterm for some reason (and I can't think of any good reason), then you could have your script launch a virtual X server, Xvfb, and your xterm could use that as its server. Since it is virtual, you can't see it or interact with it. You can grab image snapshots from it, using xwd, since Xvfb creates a virtual screen in a compatible format.

--- rod.

Last edited by theNbomr; 11-26-2011 at 05:30 PM.
Old 11-26-2011, 08:05 PM   #3
Registered: Oct 2011
Posts: 34

Original Poster
Rep: Reputation: Disabled

Thanks for the reply. This was purely an educational exercise to learn about Linux services and invoking init scripts and Sys V. At first I wanted to see if I could get a service to invoke at boot time... I then was settling for just invoking the service manually with "service start" and couldn't get past this DISPLAY problem.

if I treat and as a script, not a service (omitting the part of that is service related), when invoking is opens xterm just fine. This DISPLAY problem is something that is service specific, or I should say related to properies related to invoking a service (fork?)...

I just want to be able to start a service and have it invoke an xterm and print "Hello, world". I can do it with just bash scripts, but want to tie it to a service, and then eventually tie ir to a service that gets invoked at boot time. If someone could help me do that it would be great, just so I can learn something... ;-)


- Bill
Old 11-26-2011, 08:35 PM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,395
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Well, you don't need an xterm in order for your service to print something. Your script's standard output stream is the linux console. Whatever you print will go there. If your program needs to stay running, you can background it, or make it a daemon (there is usually a helper function in your startup scripting somewhere to help you do that).
Usually you have to launch services as root, but any running X server will be owned by a non-root user. Some X configurations cause this to prevent the root user from accessing the X server; this is probably what is going on when you have problems launching services post-boot. There are ways around that, using X authentication tools, but I can't explain how.
My suggestion is to simply not try to launch an xterm, and use existing console facilities.

--- rod.


display, service, xterm

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
xterm error display not set fordwrench Slackware 13 12-04-2012 07:28 AM
XTerm(241) support for truetype fonts and method of changing XTerm font. ajassat Linux - Software 2 08-19-2009 12:01 PM
xterm -display remote:0.0 Can't open display - xterm from tru64 to debian 3.1 loopy69 Linux - Software 2 04-01-2008 06:54 PM
xterm - howto lauch an xterm into a specific directory jobano Linux - Software 8 02-26-2008 03:18 PM
how is black xterm background in IceWM when issue a xterm command? BRAHmS Linux - Software 1 02-14-2005 03:51 AM

All times are GMT -5. The time now is 06:09 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration