Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've seen a lot of examples using dialog tools into scripts with lines as follows:

trap "rm $datafile" 0 1 2 5 15

What I don't understand is the meaning of SIGNAL 5, ok I know is SIGTRAP. But shame on me, still I don't understand its real significance...

Thanks in advance!!

share|improve this question
It's not significant now - seems to have been reused from very old scripts which worked around some buggy shell implementation on Solaris. A better choice would be signal 3. – Thomas Dickey Oct 29 '15 at 22:47
up vote 4 down vote accepted

There's a manpage signal(7):

Signal         Value   Action   Comment
SIGTRAP        5        Core    Trace/breakpoint trap

This signal (as the manpage suggests) is primarily used by debugging tools like gdb or strace, respectively the ptrace(2) system call. If one process is tracing another process's activity through ptrace(2), SIGTRAP will be heavily used to »interrupt« the child, even though the child in most cases won't effectively know this happened (a process monitored through ptrace(2) does not necessarily notice which signal had been sent to it, because of the tracer being able to intercept and filter delivered signals and SIGTRAP primarily serves to inform the tracer that something noticable happened).

Looking at the ptrace(2) manpage is very enlightening in this case.

share|improve this answer

I don't understand its real significance

Let's see how it's caused and used.

The major cause of SIGTRAP is the int3 instruction.

We can check that with:

int main() {
    return 0;

which when run outputs:

Trace/breakpoint trap (core dumped)

and has exit status 133 = 128 + 5, thus signal 5, SIGTRAP.

GDB inserts int3 instruction in the text segment, sets up ptrace, and lets the program run. When it hits int3, ptrace wakes up the parent which can the monitor the child's state.

Note that there are also hardware breakpoints, which have a different mechanism: http://stackoverflow.com/questions/8878716/what-is-the-difference-between-hardware-and-software-breakpoints

More about int3

int3 has two encodings:

  • the regular int prefix + 3 which takes up 2 bytes, int 3 in NASM
  • a special 1 byte long encoding, int3 in NASM

The one byte long encoding is fundamental for GDB. If the instruction were larger than 1 byte, it could overwrite multiple instructions, which would be messy.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.