1

I've been testing various systems on my pc, and from time to time, my Linux laptop freezes.

On Windows, when this happens, you can press Ctrl+Alt+Del to bring up Task Manager and kill the process slowing the system down, no matter how badly locked up everything else was. I don't know how this was implemented; I guess it's like an emergency command, that forcibly reserves or steals some RAM from other processes.

Some of the questions asked here have similar solutions to that, like cold rebooting, restarting only the GUI or "kill mouse" that kills anything you click on, but I don't like 'em.

I want to make Ctrl+Alt+Del or any other hotkey, no matter what, bring up a "working" terminal with root privileges in seconds, so I have full control over my PC, no matter what programs are running or how much RAM is being used. It should be an emergency app that can be used any time with guarantee it will work. Is this even possible, and how should I do it?

Zanna
  • 70,465

2 Answers2

1

If your graphical session is frozen you can switch to a TTY, assuming default settings this can be done with Ctrl+Alt+F1 to F6. The TTYs run sessions separate from the “normal” graphical one, which by default is reachable with Ctrl+Alt+F7.

In a TTY you can use e.g. killall firefox to send SIGTERM to all running firefox processes, for more see How do I kill processes in Ubuntu?.


A different approach would be to change the niceness of your preferred terminal emulator, this way it is scheduled before “normal” processes of your system. To do so, just change the command used to start it (in a desktop shortcut or menu item for instance) from e.g.

yakuake

to:

/usr/bin/nice -n -20 /usr/bin/yakuake

I use the full paths by default just to be sure it runs properly, it may should also work without them. In case you're not sure, e.g. which yakuake shows you the full path.

For a running process you can use renice to change the niceness, e.g.:

sudo renice -20 $(pidof yakuake)
dessert
  • 39,982
  • Does these TTY sessions reserve its own RAM and elevates its priority over bugged Firefox etc. programs, or will it come in view only when PC "decide" to un-lag itself anyway? If no, how can i configure them, to be TOP priority tasks when i start them? Thanks. – Kal1nauskas Oct 23 '17 at 16:17
  • The TTY sessions run by default alongside your graphical session and are quite basic, I'd expect them to react no matter what your graphical session does, but of course the system still has to (be able to) evaluate your keypress to reach the TTY in the first place. Actually that's a nice question (man nice) – you could set one TTY as your emergency TTY and run bash with a super-low niceness like nice -n -20 bash and/or (even better!) programs known to cause trouble with a higher one in the first place, like nice -n 10 firefox. – dessert Oct 23 '17 at 17:25
  • That is close to what i'm looking for. Maybe you can get a little bit more specific, on how to configure one of my TTY's or better, my default terminal emulator, to be my emergency terminal, with correct niceness that it just Pop-up when emeregency comes :) Thank you! – Kal1nauskas Oct 27 '17 at 18:13
  • @Kal1nauskas I'd simply change the command executed by the desktop shortcut (or other link) you use to start it to e.g. /usr/bin/nice -n -20/usr/bin/yakuake. This will run it (and every child I suppose) with the niceness most favorable to the process, which should allow you to use the program even while others try to eat up your system's resources. – dessert Oct 29 '17 at 10:21
  • @Kal1nauskas See my edited answer above. – dessert Oct 29 '17 at 12:01
0

Switch to a TTY

If your graphical session is frozen you can often switch to a TTY, assuming default settings this can be done with Ctrl+Alt+F1 to F6, as described in the answer by @dessert.

System Request (SysRq) sequence

Sometimes the system is so frozen, that the TTYs cannot be activated. Then you can use a System Request (SysRq) sequence. Often SysRq is invoked by the

Alt + PrintScreen keys, sometimes the Fn key is involved too (in laptops),

While pressing these keys you press the following keys slowly (maybe 1 second per key)

R E I S U B - reboot

R E I S U O - poweroff

See this link for more details,

en.wikipedia.org/wiki/Magic_SysRq_key

This is a way to poweroff or reboot linux systems gracefully, that often works to keep the file system healthy (in contrast to hard poweroff).

sudodus
  • 46,324
  • 5
  • 88
  • 152