145

Just wondering about the difference between SIGSTOP and SIGTSTP signals.

Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
user1419715
  • 1,607
  • 2
  • 12
  • 8

5 Answers5

202

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.

ave
  • 287
  • 13
  • 27
jlliagre
  • 29,783
  • 6
  • 61
  • 72
  • 24
    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. – simpleuser Jun 19 '15 at 02:01
  • @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? – jlliagre Jan 14 '19 at 08:38
  • @jlliagre I did a closer survey, and it turned out that you are right. I deleted the previous comment. – Archer Jan 14 '19 at 09:25
  • @Archer Ok, my guess is you were confused by the manual page terminology. `terminal stop` means TSTP. – jlliagre Jan 14 '19 at 09:26
  • @jlliagre I want to, but the system won't allow it, it says I can only cancel the downvote if the answer is edited… – Archer Jan 14 '19 at 12:17
  • @jlliagre 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? – Manuel Jordan May 13 '22 at 13:49
  • 1
    @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)` – jlliagre Sep 12 '22 at 06:11
  • 1
    @jlliagre interesting that scenario - huge thanks for the feedback! – Manuel Jordan Sep 12 '22 at 19:13
53

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).  */
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
Royce Chao
  • 729
  • 6
  • 5
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.

bob dylan
  • 989
  • 2
  • 10
  • 26
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.  */

Good Pen
  • 625
  • 6
  • 10
0

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.
jqgsninimo
  • 6,562
  • 1
  • 36
  • 30