1

I have 2 processes written in C, I'll call them 'parent' and 'child'. Parent creates child and child enters a loop where it does some code, then raises SIGSTOP. If a certain condition is reached, the parent needs to send the child SIGTERM, otherwise SIGCONT.

How can I send it SIGTERM while it is suspended and get exactly my desired results? By simply sending it SIGCONT then SIGTERM I'm afraid the child will reach SIGSTOP before SIGTERM is sent, and I also think the 2 signals one after the other will interfere with each other.

AdminBee
  • 22,803
Eloo
  • 79

1 Answers1

2

If you have a process in a suspended state, it won't action any signals (other than SIGKILL) until it continues. A pending signal will be queued on the process.

So depending on your situation you will need to send either:

  1. SIGTERM and then SIGCONT
  2. SIGCONT

Of course this can be simplified to

if (condition) { send SIGTERM }
send SIGCONT
Chris Davies
  • 116,213
  • 16
  • 160
  • 287