I believe the related man page is, XKillClient. You can use xdotool
to simulate the close button being clicked from a terminal like so.
Example
Assuming I have a gnome-terminal
open and it's name is "saml@grinchy:/home".
Get the window ID
$ xdotool search --name "saml@grinchy:/home"
96488188
Send it a Alt+F4
$ xdotool windowactivate --sync 96488188 key --clearmodifiers \
--delay 100 alt+F4
You can put them together by embedding the first command into the second:
$ xdotool windowactivate --sync $( ...1st command...) key --clearmodifiers \
--delay 100 alt+F4
You can save yourself by letting xdotool
do both at the same time:
$ xdotool search --name "saml@grinchy:~" key alt+f4
Globally
You can adapt what I've provided to run it on windows that have the same name:
$ xdotool search --name "saml@grinchy:~"
96488779
96468996
Or on windows by other attributes. You can use xwininfo
to find out more about a particular window. Run it and then just click on the window of interest:
$ xwininfo
xwininfo: Please select the window about which you
would like information by clicking the
mouse in that window.
xwininfo: Window id: 0x5c04d4b "saml@grinchy:~"
Absolute upper-left X: 14
Absolute upper-left Y: 74
Relative upper-left X: 14
Relative upper-left Y: 74
Width: 941
Height: 361
Depth: 32
Visual: 0x62
Visual Class: TrueColor
Border width: 0
Class: InputOutput
Colormap: 0x5c00003 (not installed)
Bit Gravity State: NorthWestGravity
Window Gravity State: NorthWestGravity
Backing Store State: NotUseful
Save Under State: no
Map State: IsViewable
Override Redirect State: no
Corners: +14+74 -485+74 -485-465 +14-465
-geometry 132x24+14+74
Other useful tools when dealing with X11 windows are xdpyinfo
& xprop
. xdpyinfo
can be used to find out information about the X server. So you can figure out which window has focus:
$ xdpyinfo |grep focus
focus: window 0x5c00005, revert to Parent
xprop
and xwininfo
can take a -id
switch so you can provide them the Window ID that you're interested in instead of having to click on it:
$ xprop -id 0x5c00001|grep -i class
WM_CLASS(STRING) = "gnome-terminal", "Gnome-terminal"
References
The instructions to disable xdm/kdm/gdm/whichever-dm-you-have is correct. If you don't do this, you boot to a graphical login (that's the dm = display manager), and then whenever you quit X (which should be as easy as ctrl-alt-backspace
-- try it, but close your apps first), the DM will respawn another graphical login, making it impossible to escape the GUI.
Another possibility with debian is to check in /etc/rc[N].d
for a runlevel which does not start the dm, and make that the initdefault
in /etc/inittab
. I don't have an unmodified debian system at hand, so I can't say which if any that will be -- possibly 2. Do not choose 0, 1, or 6.
Once the dm is disabled, you boot to a login console. From there you can start X with the command startx
. This includes a default DE and if you've been using gnome that will probably be it. You can also create an ~/.xinitrc
, which is a shell script which will be run in place of the default. Generally they can be pretty minimal, eg:
#!/bin/sh
exec gnome-session
Should start gnome (I believe -- I don't have a gnome system at hand either).
Note that you can't run a GUI application without X; it's not clear from your post you understand that. GUI programs are actually clients that need the Xorg server to work. You can start a bare X with no DE or WM and a specific application by replacing the exec gnome-session
line with the name of the application, but beware you'll then have no way to start anything else and when you close that application, you'll be looking at a blank screen with a cursor floating in it.
There's nothing dangerous in all this and it is easy to re-enable the DM if you want.
Best Answer
Usually, you can use SIGHUP to "friendly" close an application (with or without graphical interface).
EDITED: added some other info
The way SIGHUP is handled is application dependent so, as Dave noted, it can happen that this signal is masked or handled. However quite all interactive applications exit gracefully with a SIGHUP.
On the other side, I have to admit that usually I follow this schema:
Obviously the last command is not so "friendly".