If I run mysqld from the command line, it displays some startup messages, and then stops responding. It doesn't produce output, and ignores any input, and there seems to be no way to get rid of it. ctrl+z and ctrl+c don't do anything, there is no way to get back to a terminal - I have to start a new session. This means, for instance, if I am connecting to a server via ssh I have to initiate a new ssh connection.

This is very annoying. Is there any way in bash to tell it to deactivate the currently running process? Any other program I can suspend with ctrl+z, but not mysqld, though I don't know why. If I start it with mysqld & then it runs in the background and I can send signals to it normally, as long as I don't make the mistake of typing fg, and it otherwise acts like an ordinary process, so I don't know why ctrl+z has no effect on it, since I thought that was part of bash rather than being under the control of the process.

So: Is there an alternative to ctrl+z, for when ctrl+z does not work?


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.

  • I was not aware I could send SIGQUIT with a keyboard shortcut - that solves my particular problem, and stty -a is very useful generally. Just out of curiosity, do you know if there is a way to add to or change the keyboard shortcuts?
    – Benubird
    Jul 16 '15 at 7:14
  • @Benubird I never dealt myself with it, but take a look at this question: superuser.com/questions/160388/… Jul 16 '15 at 7:21
  • 1
    Ah! Thanks, don't know how it didn't occur to me to check the manpage for stty - somehow I assumed I would have to change it through a config file somewhere, but it looks like I can just use stty to set shortcuts. Thanks.
    – Benubird
    Jul 16 '15 at 7:31
  • @Benubird I edited my answer to add an answer to your previous question in these comments. Yesterday I happened to need to temporarily change a couple of mappings with stty and I remembered our discussion here. Given the time that has passed, though, I assume you figured it out already by yourself, being it quite simple ;) Aug 27 '15 at 12:52

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.

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.