unix SIGSTOP和SIGTSTP之间有什么区别?

dnph8jn4  于 2022-12-12  发布在  Unix
关注(0)|答案(5)|浏览(343)

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

wd2eg0qa

wd2eg0qa1#

这两种信号都是用来挂起一个进程,而该进程最终将使用SIGCONT恢复。它们之间的主要区别是:

  • SIGSTOP是以编程方式发送的信号(例如:kill -STOP pid),而SIGTSTP(用于signal -tterminalstop**)也可以由用户在键盘上键入(通常是Control-Z)来通过tty驱动程序发送。
  • 不能忽略SIGSTOP。可能忽略SIGTSTP
yh2wf1be

yh2wf1be2#

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

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

vd8tlhqk3#

目标进程不能忽略SIGSTOP。
一个很好的例子是视频播放器mpv,它可以忽略SIGTSTP,但不能忽略SIGSTOP
您可以使用运行以下内容的视频进行测试:
kill -SIGTSTP $(pidof mpv)kill -SIGSTOP $(pidof mpv)
当然kill -SIGCONT $(pidof mpv)恢复播放。

juzqafwq

juzqafwq4#

在ubuntu上,/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.  */
6yt4nkrj

6yt4nkrj5#

在macOS上,执行命令man signal读取信号文档。
| 编号|名称名称名称|预设动作|项目名称|
| - -|- -|- -|- -|
| 十七岁|信号停止|停止进程|stop(无法捕获或忽略)|
| 十八|信号传输协议|停止进程|键盘产生停止信号|
它们之间有两个区别:

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

相关问题