How to cleanly shutdown Eclipse from Linux command line?
Is there a way to shutdown Eclipse cleanly from the command line, such that files and workspaces are saved? kill -3 doesn't do anything. kill -1 and kill -15 (default) causes Eclipse to exit abruptly with JVM termination popup. kill -9 does the same th开发者_开发问答ing.
The use case is that I'm working remotely on a machine with Eclipse loaded on it, and I want to save memory by closing Eclipse, but I want Eclipse to save its state first.
I could use VNC or some alternative desktop sharing software, but that's really heavy-weight, and I'd much prefer a command line solution.
EDIT: System info: RHEL5.1 64-bit using GNOME
I figured this out with the help of gigi's answer and another question. You're going to need the wmctrl
and xdotool
utilities from your package manager.
Unless you're running in a terminal emulator on the same display, you need to set the right display:
$ export DISPLAY=:0.0
Then (irrelevant windows elided from example):
# List windows
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
# Tell Eclipse window to close gracefully
$ wmctrl -c eclipse
# Darn, there's a confirmation dialog
$ wmctrl -l
...
0x030000fa 0 kcirb Java - Eclipse
0x03003c2d 0 kcirb Confirm Exit
# Send return key to the window
$ xdotool key --window 0x03003c2d Return
Worked for me on Ubuntu 12.04, at least.
EDIT: See Scarabeetle's answer for the tweaks you need to make it work from a script.
Not enough reputation to comment on pidge's answer above... It almost works, but I needed to wait for some Gnome3 animation to finish and then give focus to the "Confirm Exit" window:
export DISPLAY=:0.0 # Do this in main X session
wmctrl -c "Eclipse SDK" # Close main window
sleep 1 # Wait for animation
wmctrl -a "Confirm Exit" # Give focus to the dialog
# Send a Return keypress to press the OK button
xdotool key --window $(xdotool search "Confirm Exit") Return
Any added ShutdownHooks
(more info here) should be executed by the JVM when terminated by SIGTERM
. Therefore, I think the problem is the way Eclipse is programmed to deal with such signals.
As I don't know how the cleanup process is implemented in Eclipse, I can only assume that it is not called by any ShutdownHook
(and rather by an Action
or something similar).
Edit: pidge has provided an answer below however which details steps which should allow you to shutdown Eclipse cleanly from the command line.
Try killing java process(es). Do ps -ea | grep java
Did you tried with wmctrl? wmtrl -l lists the windows and wmlctrl -c -P should close the window. Anyway you could have problems with the confirmation dialog of eclipse.
Did you try kill -HUP
(kill -1
)? -- that's the canonical way to tell a process that whoever was interacting with it has gone away and it should clean up appropriately
The answer to this question was helpful to me in a similar issue: Eclipse hanging, how to kill it properly?
After I killed the eclipse process the Eclipse window kept there until I killed the java process (I didn't have a javaw process as in the answer above. I had only one "java" process that when killed fixed the problem).
精彩评论