24

One of my problems with Ubuntu is, when my PC overloads, my Ubuntu system hangs and I try to get it to respond by opening the CD-ROM drive manually to force an interrupt and get access to the system monitor for closing some tasks.

In Windows, when this situation happens, I can usually escape it by pressing Ctrl+Alt+Del to switch into Task Manager, which usually gets me out of a hanging situation.

So, I would like to know: is there something I can do with Ubuntu to escape a hanging situation (‌like pressing Ctrl+Alt+Del on Windows)?

Update:

Acording the @Grumpy_Old_Man Info Request:

What processor are you using and how old is it. There is a known issue with early Ryzen CPUs, which hang under low load. bugzilla.kernel.org/show_bug.cgi?id=196683

My CPU information:

$ cat /proc/cpuinfo
processor   : 0
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
stepping    : 9
microcode   : 0xca
cpu MHz     : 3278.317
cache size  : 4096 KB
physical id : 0
siblings    : 4
core id     : 0
cpu cores   : 2
apicid      : 0
initial apicid  : 0
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 5808.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 1
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
stepping    : 9
microcode   : 0xca
cpu MHz     : 3274.188
cache size  : 4096 KB
physical id : 0
siblings    : 4
core id     : 1
cpu cores   : 2
apicid      : 2
initial apicid  : 2
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 5808.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 2
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
stepping    : 9
microcode   : 0xca
cpu MHz     : 3271.793
cache size  : 4096 KB
physical id : 0
siblings    : 4
core id     : 0
cpu cores   : 2
apicid      : 1
initial apicid  : 1
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 5808.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

processor   : 3
vendor_id   : GenuineIntel
cpu family  : 6
model       : 142
model name  : Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
stepping    : 9
microcode   : 0xca
cpu MHz     : 3285.540
cache size  : 4096 KB
physical id : 0
siblings    : 4
core id     : 1
cpu cores   : 2
apicid      : 3
initial apicid  : 3
fpu     : yes
fpu_exception   : yes
cpuid level : 22
wp      : yes
flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs        : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips    : 5808.00
clflush size    : 64
cache_alignment : 64
address sizes   : 39 bits physical, 48 bits virtual
power management:

And my Ubuntu Info:

 hostnamectl
   Static hostname: so-notebook
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 34a2eb65afa64d60a60ed02d972e884d
           Boot ID: 9ee34ad4bff84b908e8719ab83029836
  Operating System: Ubuntu 18.04.3 LTS
            Kernel: Linux 5.0.0-37-generic
      Architecture: x86-64

13

You can set a shortcut to open system monitor in Ubuntu with the key combination you like (in this case, Ctrl+Alt+Del).

You can set custom shortcuts for custom key combination in the Settings (by the way, these steps are for Ubuntu 18.04):

  1. Go to the Settings.
  2. Search for shortcuts (just start typing and it will search for it).
  3. Now, press on the Keyboard option and scroll down to the end.
  4. Click on the + sign and a dialog will come up.
  5. Type the name of the shortcut which can be anything you want (in this case, you can write Open System Monitor).
  6. Type the name of the command (in this case, gnome-system-monitor).
  7. Click on the Set shortcut` option and press the key combination you will use to open the System monitor (in this case, press Ctrl, Alt and Del at the same time after clicking the option).
  8. Last but not the least, click Add and a custom shortcut will be created.

You can try out the shortcut by pressing the key combination(Ctrl+Alt+Del) you assigned to the shortcut.

41

The least invasive option is to use Ctrl+Alt+F3 to switch to a console.

From the console, you can investigate what is going on using the tools you would normally use, like top, htop, free, or spelunking through the /proc and /sysfs file systems. Once your investigation has determined the culprit, you can send do whatever you need to correct the situation.

E.g. if you have a runaway process, you can try to send it the SIGTERM signal using kill -s TERM <PID>. If that doesn't work, you can be more aggressive and send it the SIGKILL signal using kill -s KILL <PID>.

If you have an SSH server set up, you can also log in remotely via SSH. Note, however, that if something on your system is going haywire, SSH might not work properly, e.g. because it can't get enough CPU time or memory or network sockets.

If you have a serial console set up, you can log in via serial terminal.

If you can't get to a console, the Linux Kernel has a feature called the "Magic SysRq Key".

The Magic SysRq Key is a way of getting the kernel's attention under almost all circumstances (the only major situation where it doesn't work is in a kernel panic, which makes sense: the kernel has crashed, it can't do any further work).

You can access the functionality of the Magic SysRq Key by holding down Alt+SysRq and typing a series of commands that are all single letters.

If you don't have a separate SysRq key, it is usually an alternate mode of the PrtScr key, even if it is not labelled. If you don't have that either, you'll have to look it up in the manual of your keyboard or your laptop.

Note that the keys are based on their scancodes on a US English QWERTY keyboard. In other words, Linux doesn't know what letter is printed on your key, it only cares about the location of the key on the keyboard. If you have a different keyboard layout, you will need to use the keys at the same position as if you had a US English QWERTY layout.

One common command sequence is:

  • r: Switch the keyboard into XLATE mode from raw mode (e.g. if you are currently in a GUI, the keyboard is most likely switched to raw and will be useless in the console).
  • e: Send the SIGTERM signal to all processes except PID 1 (init). This will nicely ask all processes to shut themselves down.
  • … wait a bit to give all processes a chance to shut down orderly.
  • i: Send the SIGKILL signal to all processes except PID 1 (init). This will very much not nicely ask all processes that are still running after the previous step to commit immediate suicide.
  • … wait a bit
  • s: sync all currently mounted file systems. This will flush the page cache and block cache to disk.
  • … wait a bit to allow the Linux kernel to flush all caches to the storage devices and the storage devices to flush all their internal caches to the medium; if you still have old-style disk activity LEDs, wait until activity dies down
  • u: umount all currently mounted file systems, or rather remount all currently mounted filesystem read-only.
  • … wait a bit
  • b: reboot or alternatively o: shutdown

The sequence could be written out as REISUB. A common mnemonic to remember it is "Reboot Even If System Utterly Broken".

  • 6
    Magic SysRq is restricted by default on Ubuntu: only r, s and u will work. The configuration is set in /etc/sysctl.d/10-magic-sysrq.conf. To apply changes after editing it use sudo sysctl --system. – Ruslan Dec 14 '19 at 16:01
  • 2
    Raising Elephants Is So Utterly Boring – Reeno Dec 16 '19 at 16:39
  • 2
    Or, "Busier" spelled backwards. Because the system is busy... – Boluc Papuccuoglu Dec 16 '19 at 19:36
  • 1
    Actually, my mistake, found after experiment: rei don't work by default, while subo do. The comment in that .conf was not easy to use to predict this. – Ruslan Dec 18 '19 at 12:12
9

Holding down Alt and SysRq (which is the Print Screen key) while slowly typing REISUB will get you safely restarted. REISUO will do a shutdown rather than a restart.

  • Won't work in default Ubuntu config, see this comment. Holding Alt and SysRq and typing will also likely have problems, see this Q&A. – Ruslan Dec 14 '19 at 16:04
  • I have a laptop that removed the SysRq key, and the shortcut is Fn+s, which makes SysRq+s impossible :-( (I usually have an external keyboard plugged into it, but when I don't and it freezes I have to just sigh and hold down the power button for up to 30 seconds :-/ ) – Aaron F Dec 15 '19 at 11:54
  • Works without any fuss in kali, how can I get my ubuntu to do the same? – endrias Dec 15 '19 at 17:45
  • someone kindly pointed out to me via github that SysRq can be virtually held down on Lenovo laptops by keeping Alt held while pressing Fn+s, and then tapping the desired magic key, finally releasing Alt. – Aaron F Dec 15 '19 at 20:17
  • 5
    @AaronF you don't have to hold SysRq all the way during the typing. It's sufficient to press and release SysRq and only hold Alt while typing the REISUB or whatever. This works on all keyboards — it's a feature of how Linux implements Magic SysRq. – Ruslan Dec 16 '19 at 9:29
5

If you know the program that is not responding, go to a TTY shell CTRL+ALT+F4 then use the following script to kill that program. Copy the code and save it as exterminate.sh in /bin

#!/bin/bash

userName=$(whoami);
programName="$1";
main(){
    pidVar=$(top -n 1 -d 1 -b | grep -i "$programName" | cut -c -6 );
    kill $pidVar >& /dev/null;
    echo "killed all \"$programName\" instances.";
}

if [ "$userName" == "root" ] ; then main ; else echo "run as root" ; fi;

then make the script executable by

sudo chmod +x /bin/exterminate.sh

and execute it as superuser. Be careful about the argument that you pass to the script as you inadvertently might end up causing more damage than you've bargained for.

e.g. if for example the malfunctioning program is transmission

sudo exterminate.sh transmission

would do the trick.

  • what does this script do that killall doesn't? – Aaron F Dec 16 '19 at 11:49
  • 1
    killall also gets stuck and worst part about it is that it won't kill itself. It can kill other killall processes but never itself. This script has nothing that could be stuck as opposed to killall which does, occasionally. – endrias Dec 16 '19 at 21:11
5

when my PC overloads, my Ubuntu system hangs

For me, this usually means running out of RAM and starting to swap heavily.

What can help in this situation is the Alt+SysRq+F combination, which commands the system to kill the task taking most memory.

You'll have to enable the SysRq key first, as explained in this question. Also some laptops require holding down Fn key simultaneously.

4

Press ctrl+alt+f3 to enter into TTY. From there it will be like a complete terminal experience. Type reboot/poweroff and press enter and it should solve your problem. Another solution would be to press ctrl+alt+f1 to lock your user and entering password again to enter into Ubuntu.

1

You may be able to use Ctrl+Alt+Backspace to kill the X server.

  • 1
    This is not enabled on some newer distros. For instance, it doesn't work on Ubuntu by default any longer. – RolandiXor Dec 16 '19 at 22:19

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.