Recently, I realized that a certain disk partition on a Linux Server that is only accessed by ssh was full. I tracked down the problem to a VNC log which had filled up the disk. Using lsof, I determined that even though the log was deleted and VNC was restarted the disk space was not returned because various processes related to the window manager had the files opened (nautilus, gnome-ses, gnome-key, metacity, gnome-pan, eggcups, bt-applet, nm-applet, pam-panel, escd, mapping-d, gnome-ter).

The suggestion from the sysadmin is to reboot the server. Actually, the GUI has only been used once to install the packaged software that the server runs so is not required for most of the time. I would rather fix the problem without rebooting if possible.

How can the GUI be restarted or even turned off gracefully from the command line to be restarted later when required?

  • What platform (distribution) are you using? – Zanchey Jan 24 '12 at 2:08
  • Makes sense. In Linux you can delete an open file. It'll appear to be gone from the file system but not removed (inode still valid) until all handles to the file have been closed. – Matt Jan 24 '12 at 3:13

On most major distros, the runlevel 5 is used for GUI environments and 3 is used for text-mode. Because of this you should be able to run the following command to bring it to text-mode:

 telinit 3

That tells the init process to head to runlevel 3. This will terminate the GUI, not terribly gracefully. To terminate it gracefully you'll have to actually connect to the GUI and log out any open sessions. However, if there is no open session and it's just sitting at the GDM login screen the above command is safe.

Changing the run-level the server boots into varies by distribution unfortunately, there is no one way to make it stick.

  • On most Fedora-based distros. Ubuntu doesn't work that way nowadays. – Magellan Jan 24 '12 at 5:38
  • Fedora and SuSE-based at least. – sysadmin1138 Jan 24 '12 at 12:29

sudo killall X11 or the like. or killall your wm

  • Welcome to Server Fault! We're a community of and for professional system administrators (et al). As such we prefer Answers to completely answer the Question, in a supportable and maintainable fashion. This might put the OP on the right path, but falls somewhat short of our normal standards. Thank you! – Chris S May 10 '14 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.