20

I know the individual uses of SIGPIPE and SIGIGN.

What does

signal(SIGPIPE, SIG_IGN);

exactly do?

P.P
  • 117,907
  • 20
  • 175
  • 238
xennygrimmato
  • 2,646
  • 7
  • 25
  • 47
  • Possible duplicate of [Program received signal SIGPIPE, Broken pipe.?](https://stackoverflow.com/questions/18935446/program-received-signal-sigpipe-broken-pipe) – iammilind May 14 '19 at 07:21

1 Answers1

21
signal(SIGPIPE, SIG_IGN);

simply ignores the signal SIGPIPE. Passing SIG_IGN as handler ignores a given signal (except the signals SIGKILL and SIGSTOP which can't caught or ignored).

As an aside, it's generally recommended to use sigaction(2) over signal(2) as sigaction offers better control and also don't need to "reset" the handler on some systems (which follow the System V signal behaviour).

P.P
  • 117,907
  • 20
  • 175
  • 238
  • Can we also unset this handler, if it was already set before? – xennygrimmato Jun 12 '15 at 09:51
  • 2
    You can call signal(2) again to reset it. For example, to reset it to default behaviour, call: `signal(SIGPIPE, SIG_DFL);`. – P.P Jun 12 '15 at 09:56
  • 6
    `signal()` also returns the previously installed handler. So a clean reset should be : `void (*old)(int); old = signal(some_signal,some_handler); ... signal(some_signal,old);`. Anyway, `signal` is the old (considered obsolete) interface, you should use `sigaction` is place. – Jean-Baptiste Yunès Jun 12 '15 at 11:59
  • How to do something in code right after you ignored SIGPIPE signal like ` printf("SIGPIPE signal detected!") ` – Lightsout Jun 01 '18 at 03:10
  • not sure I understand "ignores a given signal ignores it " – David 天宇 Wong Dec 26 '18 at 17:57
  • @David天宇Wong Hi, fixed it. Thanks. – P.P Dec 26 '18 at 20:02