47

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

如果有人有线索,我对 C 的熟悉比对 bash 的多,但是两种语言的答案都值得赞赏!

4

5 回答 5

82

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

stty -a
于 2011-07-20T16:05:17.033 回答
54

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

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

如果 shell 看到你按下了CtrlC,那么shell 就会发送中断信号。但这实际上只是 shell 所做的事情,而不是由于组合键而神奇地发生的事情。

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

于 2011-07-20T15:29:00.537 回答
23

来自维基百科

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

Ctrlx Ctrlr: 读入 inputrc 文件的内容,并合并在那里找到的任何绑定或变量赋值。

Ctrlx Ctrlu:增量撤消,每行单独记住。

Ctrlx Ctrlv:显示有关当前 bash 实例的版本信息。

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

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

假设你有:

$ ls *

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

$ ls dir1 dir2 file1 file2 file3`

对于我上面描述的用法,您也可以参考SuperUser 上的这个主题。

于 2013-01-10T10:12:48.373 回答
17

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

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

  • VINTR(通常CtrlC)生成一个SIGINT(被用户打断)。
  • VQUIT(通常Ctrl\)生成一个SIGQUIT(像 SIGINT,但也转储核心)。
  • VSUSP(通常CtrlZ)生成一个SIGTSTP(通过终端 I/O 停止)。
  • VDSUSP(在某些系统上,而不是在 Linux 上)SIGTSTP在程序尝试读取它时生成一个。

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

于 2011-07-20T16:02:03.913 回答
7

在 Linux/Unix 上有信号。Ctrl+C一 ( )对SIGINT我来说很明显......

如果您需要系统上可用的信号列表,那么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 ())
于 2014-02-23T22:18:10.773 回答