What is the difference between SIGSTOP and SIGTSTP?
Asked Answered
C

5

155

Just wondering about the difference between SIGSTOP and SIGTSTP signals.

Cramfull answered 9/8, 2012 at 15:31 Comment(0)
U
210

Both signals are designed to suspend a process which will be eventually resumed with SIGCONT. The main differences between them are:

  • SIGSTOP is a signal sent programmatically (eg: kill -STOP pid ) while SIGTSTP (for signal - terminal stop) may also be sent through the tty driver by a user typing on a keyboard, usually Control-Z.

  • SIGSTOP cannot be ignored. SIGTSTP might be.

Uruguay answered 9/8, 2012 at 16:41 Comment(8)
Factoid: If you're a linux programmer, SIGTSTP is what you get when you use Ctrl-Z to interrupt a process running in a shell without killing it. This usually causes the shell to put it on a suspended job list.Seabrook
@Archer I'm not sure to understand your comment. Do you mean you believe Control-Z doesn't trigger SIGTSTP or do you think it should not?Uruguay
@Uruguay I did a closer survey, and it turned out that you are right. I deleted the previous comment.Religieux
@Religieux Ok, my guess is you were confused by the manual page terminology. terminal stop means TSTP.Uruguay
@Uruguay I want to, but the system won't allow it, it says I can only cancel the downvote if the answer is edited…Religieux
@Uruguay if I understood correctly - SIGSTOP can be send only through command kill -STOP pid and SIGTSTP can be send in 2 ways, through command and by ctrl + z - Am I correct?Knowhow
@ManuelJordan SIGSTOP can be sent by most programming languages, not only the shell. For example in python, that would be os.kill(pid, signal.SIGSTOP)Uruguay
@Uruguay interesting that scenario - huge thanks for the feedback!Knowhow
H
54

According with the /usr/include/x86_64-linux-gnu/bits/signum.h file exists the following:

#define SIGSTOP     19  /* Stop, unblockable (POSIX).  */
#define SIGTSTP     20  /* Keyboard stop (POSIX).  */
Hector answered 22/4, 2013 at 2:10 Comment(2)
On Solaris 10, the signals are defined in the header file /usr/include/sys/iso/signal_iso.hRedfin
In FreeBSD 11 it's at /usr/include/sys/signal.hEmotionalism
C
3

SIGSTOP can't be ignored by the targetted process.

A good example of that is the video player mpv, it can ignore SIGTSTP but not SIGSTOP.

You can test with a video running :

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

Of course kill -SIGCONT $(pidof mpv) to resume playing.

Cero answered 30/9, 2018 at 5:56 Comment(0)
C
2

on macOS, execute command man signal to read signal documentation.

# Name Default Action Description
17 SIGSTOP stop process stop (cannot be caught or ignored)
18 SIGTSTP stop process stop signal generated from keyboard

There are two differences between them:

  • SIGTSTP can be caught or ignored, SIGSTOP cannot.
  • SIGTSTP can be generated from keyboard (CTRL+Z), SIGSTOP cannot.
Charybdis answered 6/12, 2022 at 3:20 Comment(0)
N
0

on 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.  */

Noble answered 8/1, 2022 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.