繁体   English   中英

SIGSTOP 和 SIGTSTP 有什么区别?

[英]What is the difference between SIGSTOP and SIGTSTP?

只是想知道SIGSTOPSIGTSTP信号之间的区别。

这两个信号都旨在暂停一个最终将通过SIGCONT恢复的进程。 它们之间的主要区别是:

  • SIGSTOP是一种以编程方式发送的信号(例如: kill -STOP pid ),而SIGTSTP (用于信号-终端停止)也可以由用户在键盘上键入(通常是Control - Z )通过tty驱动程序发送。

  • SIGSTOP不能被忽略。 SIGTSTP可能是。

根据/usr/include/x86_64-linux-gnu/bits/signum.h文件存在以下内容:

#define SIGSTOP     19  /* Stop, unblockable (POSIX).  */
#define SIGTSTP     20  /* Keyboard stop (POSIX).  */

目标进程不能忽略 SIGSTOP。

一个很好的例子是视频播放器mpv ,它可以忽略SIGTSTP但不能忽略SIGSTOP

您可以使用正在运行的视频进行测试:

kill -SIGTSTP $(pidof mpv)kill -SIGSTOP $(pidof mpv)

当然kill -SIGCONT $(pidof mpv)继续播放。

在 ubuntu 上,/usr/include/x86_64-linux-gnu/bits/ /usr/include/x86_64-linux-gnu/bits/signum-generic.h

#ifdef __USE_XOPEN
# define SIG_HOLD ((__sighandler_t) 2)  /* Add signal to hold mask.  */
#endif

/* We define here all the signal names listed in POSIX (1003.1-2008);
   as of 1003.1-2013, no additional signals have been added by POSIX.
   We also define here signal names that historically exist in every
   real-world POSIX variant (e.g. SIGWINCH).

   Signals in the 1-15 range are defined with their historical numbers.
   For other signals, we use the BSD numbers.
   There are two unallocated signal numbers in the 1-31 range: 7 and 29.
   Signal number 0 is reserved for use as kill(pid, 0), to test whether
   a process exists without sending it a signal.  */

/* ISO C99 signals.  */
#define SIGINT      2   /* Interactive attention signal.  */
#define SIGILL      4   /* Illegal instruction.  */
#define SIGABRT     6   /* Abnormal termination.  */
#define SIGFPE      8   /* Erroneous arithmetic operation.  */
#define SIGSEGV     11  /* Invalid access to storage.  */
#define SIGTERM     15  /* Termination request.  */

/* Historical signals specified by POSIX. */
#define SIGHUP      1   /* Hangup.  */
#define SIGQUIT     3   /* Quit.  */
#define SIGTRAP     5   /* Trace/breakpoint trap.  */
#define SIGKILL     9   /* Killed.  */
#define SIGBUS      10  /* Bus error.  */
#define SIGSYS      12  /* Bad system call.  */
#define SIGPIPE     13  /* Broken pipe.  */
#define SIGALRM     14  /* Alarm clock.  */

/* New(er) POSIX signals (1003.1-2008, 1003.1-2013).  */
#define SIGURG      16  /* Urgent data is available at a socket.  */
#define SIGSTOP     17  /* Stop, unblockable.  */
#define SIGTSTP     18  /* Keyboard stop.  */
#define SIGCONT     19  /* Continue.  */
#define SIGCHLD     20  /* Child terminated or stopped.  */
#define SIGTTIN     21  /* Background read from control terminal.  */
#define SIGTTOU     22  /* Background write to control terminal.  */
#define SIGPOLL     23  /* Pollable event occurred (System V).  */
#define SIGXCPU     24  /* CPU time limit exceeded.  */
#define SIGXFSZ     25  /* File size limit exceeded.  */
#define SIGVTALRM   26  /* Virtual timer expired.  */
#define SIGPROF     27  /* Profiling timer expired.  */
#define SIGUSR1     30  /* User-defined signal 1.  */
#define SIGUSR2     31  /* User-defined signal 2.  */

在 macOS 上,执行命令man signal以阅读信号文档。

# 姓名 默认操作 描述
17 信号停止 停止进程 停止(不能被捕获或忽略)
18 信号传输协议 停止进程 键盘产生的停止信号

它们之间有两个区别:

  • SIGTSTP可以被捕获或忽略, SIGSTOP不能。
  • SIGTSTP可以从键盘( CTRL + Z )生成, SIGSTOP不能。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM