1

I was reading this question and learned that 'select' is not reentrant. So what happens if a signal is delivered (for example SIGKILL) while we're in the middle of it. Does this mean we can never use it again?

I'm trying to solve this issue which I'm having with read and though maybe it's because of this.

Community
  • 1
  • 1
kptlronyttcna
  • 1,461
  • 1
  • 16
  • 22
  • SIGKILL is the Avada Kedavra of signals. If you get that signal, you're dead and your mom's love won't protect you. – Petr Skocik Feb 08 '17 at 07:26

1 Answers1

4

If a signal is delivered in the middle of a call to select, then the select will return -1, and set the errno to EINTR. That ends the call to select, and you're free to call select again.

What you can't do is call select inside of the signal handler. Because in that case you're calling select before the first select has returned. But of course, it makes no sense to call select in a signal handler, so you would never do that anyways.

Bottom line: if the signal is handled properly, there's no reason why you can't call select again after the signal.

user3386109
  • 34,287
  • 7
  • 49
  • 68
  • What if the signal is SIGKILL? How can `select` handle SIGKILL? – kptlronyttcna Feb 08 '17 at 10:21
  • @kptlronyttcna I admit that I ignored your choice of example for the signal, because if your program receives a SIGKILL, then it is terminated. In which case, the question doesn't make any sense. – user3386109 Feb 08 '17 at 10:27
  • the problem is that after SIGKILL I can no longer use `read` or `select`. Even if I close the program and open it again. – kptlronyttcna Feb 08 '17 at 10:35
  • @kptlronyttcna Yes, I read the other question, but I don't have an answer for it. There's not enough code in that question for someone to reproduce the problem. So it's hard to know what went wrong. – user3386109 Feb 08 '17 at 10:40