Linux ctrl-x 在终端中使用时发送哪个信号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6764265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:09:48  来源:igfitidea点击:

Which signal does ctrl-x send when used in a terminal?

linuxbashsignalssignal-handlingctrl

提问by imacake

On Linux/Unix there are signals. The CtrlCone (SIGINT) is obvious to me. Now, in some other applications there are signals via CtrlX?! Is that even a signal or does it generate an escape sequence? Is there anything else I can use as something similar to CtrlC( CtrlV, CtrlX...)?

在 Linux/Unix 上有信号。在CtrlC一个(SIGINT)是显而易见的我。现在,在其他一些应用中,信号通过CtrlX?! 这甚至是一个信号还是它会生成一个转义序列?还有什么我可以用作类似于CtrlC( CtrlV, CtrlX...) 的东西吗?

If anyone has a clue, im familiar with C more than bash, but answers in both languages are appreciated!

如果有人有线索,我对 C 比 bash 更熟悉,但对两种语言的答案表示赞赏!

采纳答案by jfg956

To get all the terminal control character assignments:

要获取所有终端控制字符分配:

stty -a

回答by Damon

There is possibly a misunderstanding. CtrlCdoes not generate a signal. It is perfectly possible to press CtrlCanywhere, and no bad things will happen (for example in every text editor or word processor, that's the de-facto-standard for "copy").

可能有误会。CtrlC不产生信号。完全可以按CtrlC任何地方,并且不会发生坏事(例如在每个文本编辑器或文字处理器中,这是“复制”的事实上的标准)。

However, when you run a program in the shell, then your keypresses really go into the shell, not into your program. The shell will forward (almost) everything to your program's stdin, and forward anything coming from stdout to either the terminal or another process or a file (if you used a pipe or redirection).

但是,当您在 shell 中运行程序,您的按键实际上会进入 shell,而不是进入您的程序。shell 会将(几乎)所有内容转发到程序的 stdin,并将来自 stdout 的任何内容转发到终端或另一个进程或文件(如果您使用管道或重定向)。

If the shell sees you press CtrlC, then the shell sends the interrupt signal. But that's really just something the shell does, not something that magically happens because of the key combination.

如果 shell 看到您按下CtrlC,则shell 发送中断信号。但这实际上只是 shell 所做的事情,而不是因为组合键而神奇地发生的事情。

About CtrlX, you probably meant CtrlZ. This stops a process, and the shell outputs a number which you can use with fgto make it run again.

关于CtrlX,你大概是说CtrlZ。这会停止一个进程,shell 会输出一个数字,您可以使用该数字fg使其再次运行。

回答by ninjalj

The terminal assigns special meaning to certain key sequences. This include deleting a character, deleting to the start of line ( CtrlU), ...

终端赋予某些按键序列特殊的含义。这包括删除一个字符、删除到行首 ( CtrlU)、...

Specifically, when the terminal ISIGlocal mode is enabled:

具体来说,当终端ISIG本地模式开启时:

  • VINTR(usually CtrlC) generates a SIGINT(interrupted by user).
  • VQUIT(usually Ctrl\) generates a SIGQUIT(like SIGINT, but also dump core).
  • VSUSP(usually CtrlZ) generates a SIGTSTP(stop by terminal I/O).
  • VDSUSP(on some systems, not on Linux) generates a SIGTSTPwhen the program tries to read it.
  • VINTR(通常CtrlC)生成SIGINT(被用户打断)。
  • VQUIT(通常Ctrl\)生成SIGQUIT(如 SIGINT,但也转储核心)。
  • VSUSP(通常CtrlZ)生成SIGTSTP(通过终端 I/O 停止)。
  • VDSUSP(在某些系统上,而不是在 Linux 上)SIGTSTP当程序试图读取它时会生成一个。

The above are configurable. This is documented on the termios(3)manpage.

以上是可配置的。这记录在termios(3)联机帮助页中。

回答by Nobilis

From Wikipedia

来自维基百科

CtrlxCtrle: Edits the current line in the $EDITOR program, or vi if undefined.

CtrlxCtrlr: Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there.

CtrlxCtrlu: Incremental undo, separately remembered for each line.

CtrlxCtrlv: Display version information about the current instance of bash.

CtrlxCtrlx: Alternates the cursor with its old position. (C-x, because x has a crossing shape).

CtrlxCtrle: 编辑 $EDITOR 程序中的当前行,如果未定义,则编辑 vi。

CtrlxCtrlr:读入 inputrc 文件的内容,并合并在那里找到的任何绑定或变量分配。

CtrlxCtrlu: 增量撤销,每行单独记住。

CtrlxCtrlv: 显示当前 bash 实例的版本信息。

CtrlxCtrlx: 将光标与其旧位置交替。(Cx,因为x 具有交叉形状)。

One additional usage of Ctrlxis to expand the *when typing a command in the shell.

的另一种用法Ctrlx*在 shell 中键入命令时扩展。

Say you have:

说你有:

$ ls *

Pressing Ctrlxand then *will expand *to all items in the current directory to something like this:

Ctrlx然后*将扩展*到当前目录中的所有项目,如下所示:

$ ls dir1 dir2 file1 file2 file3`

You can also refer to this topic on SuperUserfor the usage I described above.

您还可以参考SuperUser上的这个主题,了解我上面描述的用法。

回答by jww

On Linux/Unix there are signals. The Ctrl+Cone (SIGINT) is obvious to me...

在 Linux/Unix 上有信号。在Ctrl+C一个(SIGINT)的明显,我...

If you need a list of signals available on your system, then signum.hcan be helpful. Below is from Debian 7.3:

如果您需要系统上可用的信号列表,那么signum.h可能会有所帮助。以下来自 Debian 7.3:

/* Signals.  */
#define SIGHUP      1   /* Hangup (POSIX).  */
#define SIGINT      2   /* Interrupt (ANSI).  */
#define SIGQUIT     3   /* Quit (POSIX).  */
#define SIGILL      4   /* Illegal instruction (ANSI).  */
#define SIGTRAP     5   /* Trace trap (POSIX).  */
#define SIGABRT     6   /* Abort (ANSI).  */
#define SIGIOT      6   /* IOT trap (4.2 BSD).  */
#define SIGBUS      7   /* BUS error (4.2 BSD).  */
#define SIGFPE      8   /* Floating-point exception (ANSI).  */
#define SIGKILL     9   /* Kill, unblockable (POSIX).  */
#define SIGUSR1     10  /* User-defined signal 1 (POSIX).  */
#define SIGSEGV     11  /* Segmentation violation (ANSI).  */
#define SIGUSR2     12  /* User-defined signal 2 (POSIX).  */
#define SIGPIPE     13  /* Broken pipe (POSIX).  */
#define SIGALRM     14  /* Alarm clock (POSIX).  */
#define SIGTERM     15  /* Termination (ANSI).  */
#define SIGSTKFLT   16  /* Stack fault.  */
#define SIGCLD      SIGCHLD /* Same as SIGCHLD (System V).  */
#define SIGCHLD     17  /* Child status has changed (POSIX).  */
#define SIGCONT     18  /* Continue (POSIX).  */
#define SIGSTOP     19  /* Stop, unblockable (POSIX).  */
#define SIGTSTP     20  /* Keyboard stop (POSIX).  */
#define SIGTTIN     21  /* Background read from tty (POSIX).  */
#define SIGTTOU     22  /* Background write to tty (POSIX).  */
#define SIGURG      23  /* Urgent condition on socket (4.2 BSD).  */
#define SIGXCPU     24  /* CPU limit exceeded (4.2 BSD).  */
#define SIGXFSZ     25  /* File size limit exceeded (4.2 BSD).  */
#define SIGVTALRM   26  /* Virtual alarm clock (4.2 BSD).  */
#define SIGPROF     27  /* Profiling alarm clock (4.2 BSD).  */
#define SIGWINCH    28  /* Window size change (4.3 BSD, Sun).  */
#define SIGPOLL     SIGIO   /* Pollable event occurred (System V).  */
#define SIGIO       29  /* I/O now possible (4.2 BSD).  */
#define SIGPWR      30  /* Power failure restart (System V).  */
#define SIGSYS      31  /* Bad system call.  */
#define SIGUNUSED   31

#define _NSIG       65  /* Biggest signal number + 1
                   (including real-time signals).  */

#define SIGRTMIN        (__libc_current_sigrtmin ())
#define SIGRTMAX        (__libc_current_sigrtmax ())