简体   繁体   English

SIGSTOP 和 SIGTSTP 有什么区别?

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

Just wondering about the difference between SIGSTOP and SIGTSTP signals.只是想知道SIGSTOPSIGTSTP信号之间的区别。

Both signals are designed to suspend a process which will be eventually resumed with SIGCONT .这两个信号都旨在暂停一个最终将通过SIGCONT恢复的进程。 The main differences between them are:它们之间的主要区别是:

  • SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for sig nal - t erminal stop ) may also be sent through the tty driver by a user typing on a keyboard, usually Control - Z . SIGSTOP是一种以编程方式发送的信号(例如: kill -STOP pid ),而SIGTSTP (用于信号-终端停止)也可以由用户在键盘上键入(通常是Control - Z )通过tty驱动程序发送。

  • SIGSTOP cannot be ignored. SIGSTOP不能被忽略。 SIGTSTP might be. SIGTSTP可能是。

According with the /usr/include/x86_64-linux-gnu/bits/signum.h file exists the following:根据/usr/include/x86_64-linux-gnu/bits/signum.h文件存在以下内容:

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

SIGSTOP can't be ignored by the targetted process.目标进程不能忽略 SIGSTOP。

A good example of that is the video player mpv , it can ignore SIGTSTP but not SIGSTOP .一个很好的例子是视频播放器mpv ,它可以忽略SIGTSTP但不能忽略SIGSTOP

You can test with a video running :您可以使用正在运行的视频进行测试:

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

Of course kill -SIGCONT $(pidof mpv) to resume playing.当然kill -SIGCONT $(pidof mpv)继续播放。

on ubuntu, /usr/include/x86_64-linux-gnu/bits/signum-generic.h在 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.  */

on macOS, execute command man signal to read signal documentation.在 macOS 上,执行命令man signal以阅读信号文档。

# # Name姓名 Default Action默认操作 Description描述
17 17 SIGSTOP信号停止 stop process停止进程 stop (cannot be caught or ignored)停止(不能被捕获或忽略)
18 18 SIGTSTP信号传输协议 stop process停止进程 stop signal generated from keyboard键盘产生的停止信号

There are two differences between them:它们之间有两个区别:

  • SIGTSTP can be caught or ignored, SIGSTOP cannot. SIGTSTP可以被捕获或忽略, SIGSTOP不能。
  • SIGTSTP can be generated from keyboard ( CTRL + Z ), SIGSTOP cannot. SIGTSTP可以从键盘( CTRL + Z )生成, SIGSTOP不能。

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

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