Some things won't respond to Ctrl+C; in that case, you can also do Ctrl+Z which stops the process and then kill %1 - or even fg to go back to it. Read the section in man bash entitled "JOB CONTROL" for more information. It's very helpful. (If you're not familiar with man or the man pager, you can search using /. man bash then inside it /JOB CONTROLEnter will start searching, n will find the next match which is the right section.)

Answer from Chris Morgan on Stack Overflow
Top answer
1 of 2
2

The command stty -a will show you all keyboard shortcuts in your current terminal. Generally in Unix-like systems, the only signals mapped are Ctrl+C (SIGINT), Ctrl+\ (SIGQUIT), and Ctrl+Z (SIGTSTP). There are no other bindings to other signals, and therefore no other signals that you can send within your current session with the keyboard.

Generally speaking, the final d in a program's name usually indicates "daemon". Daemons are intended to run in background and operate through other means beyond stdin/out (like pipes, signals, sockets...). That means that it could be that you get unexpected behavior when the program itself is not running in background (like the terminal seems to "hang", because the daemon has done something to the input, output, or it's doing something/waiting in a loop)

Also generally, it could be as well that the daemon has traps for specific signals and handles them differently (or even ignores them). Have you tried to send SIGINT (kill -2, equivalent to Ctrl+C), SIGQUIT (kill -3, equivalent to Ctrl+\), or SIGTSTP (kill -20, equivalent to Ctrl+Z) while running mysqld in background, just for testing purposes?

EDIT: To change stty mappings, you'll need to write:

stty <action> <new-mapping>

For example, to remap SIGINT to Ctrl+X

stty intr ^x

Note that this setting is only valid in the current terminal during the current session.

2 of 2
0

Ctrl+Z is actually a feature of the generic terminal interface in the kernel, not of bash. It causes a SIGTSTP signal to be sent to the foreground process. Likewise Ctrl+C sends SIGTERM and Ctrl+\ sends SIGQUIT.

There are two ways in which a program can cause Ctrl+Z to lose its effect.

  • The program can ignore the SIGTSTP signal.
    You can check the a process's signal behavior with a debugger. On Linux, the information is available via /proc: grep Sig /proc/1234/status where 1234 is the process ID shows which signals are ignored (SigIgn, they'll just bounced off harmlessly) or blocked (SigBlk, they're put in wait until the program lets them in). The number is a bitmask and written out in hexadecimal. SIGTSTP is signal 20 (run kill -l in bash) so it is ignored if on the SigIgn line, the fifth digit from the right is 8 or above.
  • The program can change the key bindings.
    You can check the current key bindings with a command line like stty -a </dev/pts/42 where /dev/pts/42 is the terminal where the process is running. Look for susp = ^Z.

A daemon is likely to ignore most signals. Launch it in the background, if it doesn't fork by itself (most daemons actually fork a child as soon as they start and let the parent immediately). If you launched it in the foreground, there are many ways to recover (send it or its parent shell a signal) but you'll need another shell for that.

Top answer
1 of 2
15

As far as I know, the only signals that have a default keyboard shortcut in the shell are SIGINT (Ctrl + C) to stop a process and SIGTSTP (Ctrl + Z) to pause one.

Apparently, as Radu Rădeanu just taught me, there is also Ctrl+\ which is mapped to SIGQUIT.

You can find a list of all signals and what they do in man 7 signal:

   Signal     Value     Action   Comment
   ──────────────────────────────────────────────────────────────────────
   SIGHUP        1       Term    Hangup detected on controlling terminal
                                 or death of controlling process
   SIGINT        2       Term    Interrupt from keyboard
   SIGQUIT       3       Core    Quit from keyboard
   SIGILL        4       Core    Illegal Instruction
   SIGABRT       6       Core    Abort signal from abort(3)
   SIGFPE        8       Core    Floating point exception
   SIGKILL       9       Term    Kill signal
   SIGSEGV      11       Core    Invalid memory reference
   SIGPIPE      13       Term    Broken pipe: write to pipe with no
                                 readers
   SIGALRM      14       Term    Timer signal from alarm(2)

   SIGTERM      15       Term    Termination signal
   SIGUSR1   30,10,16    Term    User-defined signal 1
   SIGUSR2   31,12,17    Term    User-defined signal 2
   SIGCHLD   20,17,18    Ign     Child stopped or terminated
   SIGCONT   19,18,25    Cont    Continue if stopped
   SIGSTOP   17,19,23    Stop    Stop process
   SIGTSTP   18,20,24    Stop    Stop typed at terminal
   SIGTTIN   21,21,26    Stop    Terminal input for background process
   SIGTTOU   22,22,27    Stop    Terminal output for background process
   SIGBUS      10,7,10     Core    Bus error (bad memory access)
   SIGPOLL                 Term    Pollable event (Sys V).
                                   Synonym for SIGIO
   SIGPROF     27,27,29    Term    Profiling timer expired
   SIGSYS      12,31,12    Core    Bad argument to routine (SVr4)
   SIGTRAP        5        Core    Trace/breakpoint trap
   SIGURG      16,23,21    Ign     Urgent condition on socket (4.2BSD)
   SIGVTALRM   26,26,28    Term    Virtual alarm clock (4.2BSD)
   SIGXCPU     24,24,30    Core    CPU time limit exceeded (4.2BSD)
   SIGXFSZ     25,25,31    Core    File size limit exceeded (4.2BSD)

   SIGIOT         6        Core    IOT trap. A synonym for SIGABRT
   SIGEMT       7,-,7      Term
   SIGSTKFLT    -,16,-     Term    Stack fault on coprocessor (unused)
   SIGIO       23,29,22    Term    I/O now possible (4.2BSD)
   SIGCLD       -,-,18     Ign     A synonym for SIGCHLD
   SIGPWR      29,30,19    Term    Power failure (System V)
   SIGINFO      29,-,-             A synonym for SIGPWR
   SIGLOST      -,-,-      Term    File lock lost (unused)
   SIGWINCH    28,28,20    Ign     Window resize signal (4.3BSD, Sun)
   SIGUNUSED    -,31,-     Core    Synonymous with SIGSYS

You can see the signals that are available on your system with kill -l:

$ kill -l
 1) SIGHUP      2) SIGINT        3) SIGQUIT      4) SIGILL      5) SIGTRAP
 6) SIGABRT     7) SIGBUS        8) SIGFPE       9) SIGKILL     10) SIGUSR1
11) SIGSEGV     12) SIGUSR2     13) SIGPIPE     14) SIGALRM     15) SIGTERM
16) SIGSTKFLT   17) SIGCHLD     18) SIGCONT     19) SIGSTOP     20) SIGTSTP
21) SIGTTIN     22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO       30) SIGPWR
31) SIGSYS      34) SIGRTMIN    35) SIGRTMIN+1  36) SIGRTMIN+2  37) SIGRTMIN+3
38) SIGRTMIN+4  39) SIGRTMIN+5  40) SIGRTMIN+6  41) SIGRTMIN+7  42) SIGRTMIN+8
43) SIGRTMIN+9  44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9  56) SIGRTMAX-8  57) SIGRTMAX-7
58) SIGRTMAX-6  59) SIGRTMAX-5  60) SIGRTMAX-4  61) SIGRTMAX-3  62) SIGRTMAX-2
63) SIGRTMAX-1  64) SIGRTMAX    

Note that there are many SIGRTMAX and SIGRTMIN signals, the Linux kernel supports 32 different signals but the range of signals actually supported will depend on the glibc implementation on your system.

2 of 2
7

The SIGQUIT signal is similar to SIGINT (produced by Ctrl+C), except that it's controlled by a different key — the QUIT character, usually Ctrl+\ — and produces a core dump when it terminates the process, just like a program error signal. You can think of this as a program error condition "detected" by the user.

So, Ctrl+\ (Ctrl + Backslash) may be what you want.

Reference: Termination Signals.

🌐
Linux Kernel Labs
linux-kernel-labs.github.io › refs › heads › master › lectures › interrupts.html
Interrupts — The Linux Kernel documentation
Select and arrange the commands or output of the commands in the correct order. (void *) 0xc15de780 <entry_SYSENTER_32> set $idtr_addr=($idtr_entry>>48<<16)|($idtr_entry&0xffff) print (void*)$idtr_addr set $idtr = 0xff800000 (void *) 0xc15de874 <entry_INT80_32> set $idtr = 0xff801000 set $idtr_entry = *(uint64_t*)($idtr + 8 * 128) monitor info registers · In Linux the interrupt handling is done in three phases: critical, immediate and deferred.
🌐
Stack Overflow
stackoverflow.com › questions › 71539995 › how-to-use-interrupt-function-in-ubuntu-20
c - how to use interrupt function in Ubuntu 20? - Stack Overflow
linux-source - Linux kernel source ... with Ubuntu patches · NEW EDITED: I tried as below, it was just the same like days ago when I copied files to a folder: gcc irq.c -include /usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/interrupt.h /usr/src/linux-hwe-5.13-headers-5.13.0-35/include/linux/irqreturn.h In file included from <command-line>:32: ...
Find elsewhere
🌐
Medium
medium.com › @18bhavyasharma › command-working-behind-the-ctrl-c-and-ctrl-z-interrupt-signals-in-linux-c5d802f914f3
Command Working Behind the Ctrl+C and Ctrl+Z Interrupt Signals in Linux | by bhavya sharma | Medium
October 29, 2024 - They enable the kernel to communicate with running processes, and allow users to control these processes efficiently. Some common signals include: SIGINT (2): Interrupts a process (ctrl+c).
🌐
nixCraft
cyberciti.biz › nixcraft › howto › bash shell › how to stop/interrupt cp or mv linux or unix command
How to stop/Interrupt cp or mv Linux or Unix command - nixCraft
August 16, 2017 - A user can stop or interrupt any command such as cp, mv and others by pressing CTRL–c (press and hold ctrl key followed by c) during the execution of a command or bash/perl/python script.
🌐
Learn Ubuntu
learnubuntu.com › stop-running-command
How to Stop a Running Command in Ubuntu
May 12, 2024 - I interrupted a ping command from executing further using the Ctrl+C shortcut. It induces a termination signal on the currently running process, which interrupts the process from continuing further.
🌐
TREND OCEANS
trendoceans.com › home › blog › topic › interrupt or suspend a command execution in linux
Interrupt or Suspend a Command Execution in Linux - TREND OCEANS
January 8, 2022 - How to copy file from local to remote server in linux · Most of the time, you executed the rm command or transfer files using the mv or cp commands. To interrupt the command further from execution, you might want to stop them immediately.
🌐
Linux Journal
linuxjournal.com › content › watch-live-interrupts
Watch Live Interrupts | Linux Journal
June 22, 2009 - # watch -n1 "cat /proc/interrupts" CPU0 CPU1 0: 330 0 IO-APIC-edge timer 1: 11336 0 IO-APIC-edge i8042 4: 2 0 IO-APIC-edge 6: 3 0 IO-APIC-edge floppy ... NMI: 0 0 Non-maskable interrupts LOC: 5806923 6239132 Local timer interrupts ... The watch command executes another command periodically, ...
🌐
EmbeTronicX
embetronicx.com › tutorials › linux › device-drivers › linux-device-driver-tutorial-part-13-interrupt-example-program-in-linux-kernel
Interrupts Example Program in Linux Kernel – Linux Device Driver Tutorial - Part 13
September 24, 2023 - We can able to see the print “Shared IRQ: Interrupt Occurred“ ... If you are using the newer Linux kernel, then this may not work properly. You may get something like below. ... In order to solve that, you have to change the Linux kernel source code, Compile it, then install it. Note: The complete process will take more than an hour and you need to download the Linux kernel source also. Step 1: Previously, I have used an old kernel. Now I am updating the kernel to 5.4.47 with Ubuntu ...
Top answer
1 of 1
2

I'd recommend trying to search for an answer before asking a question. This is shamelessly copy/pasted from http://www.linuxjournal.com/content/watch-live-interrupts.

To see the interrupts occurring on your system, run the command:

watch -n1 "cat /proc/interrupts"

The watch command executes another command periodically, in this case "cat /proc/interrups". The -n1 option tells watch to execute the command every second.

Try using -d for fancy output with highlights.


Man page link for the watch command: http://linux.die.net/man/1/watch


Introduction to Linux Interrupts (describes what /proc/interrupts is all about):http://www.thegeekstuff.com/2014/01/linux-interrupts/

  • The first Column is the IRQ number.
  • The Second column says how many times the CPU core has been interrupted.
  • For interrupt like rtc [Real time clock] CPU has not being interrupted. RTC are present in electronic devices to keep track of time. NMI and LOC are drivers used on system that are not accessible/configured by user.
  • IRQ number determines the priority of the interrupt that needs to be handled by the CPU.

A small IRQ number value means higher priority.

For example if CPU receives interrupt from Keyboard and system clock simultaneously. CPU will serve System Clock first since it has IRQ number 0.

IRQ 0 — system timer (cannot be changed);

IRQ 1 — keyboard controller (cannot be changed)

IRQ 3 — serial port controller for serial port 2 (shared with serial port 4, if present);

IRQ 4 — serial port controller for serial port 1 (shared with serial port 3, if present);

IRQ 5 — parallel port 2 and 3 or sound card;

IRQ 6 — floppy disk controller;

IRQ 7 — parallel port 1. It is used for printers or for any parallel port if a printer is not present.


For Windows

Original Question: How can I find out what is causing interrupts on Windows?

There are a couple of answers there you may benefit from. Like Windows Process Explorer which shows how much processor time is spent serving interrupts, Windows Performance Analyzer (WPA), the xperf command, and The DPC/ISR Action

🌐
Stack Exchange
unix.stackexchange.com › questions › 681200 › how-to-interrupt-command-initramfs
how to interrupt command initramfs - Unix & Linux Stack Exchange
December 12, 2021 - What you're seeing is a side effect of the computer reading data from disk much, much faster than it can display in text form. Even though Ctrl+C should technically work, the problem is that there is just so much data already read and "in the pipeline" going to the display that you won't be seeing the effect of the keyboard interrupt very soon.