0

In a process controlled by Supervisor, I fork child process

for i in xrange(MANAGER_PROCESS_NUM):
    p = gipc.start_process(target=daemon_process, args=())
    record.append(p)
for r in record:
    r.join()

then in each child process, I create grandchild process:

w = gipc.start_process(target=self._pool_worker, daemon=True)

How can I kill all the child processes & grandchild processes when I run "supervisorctl stop xxx" to stop my main process?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
fanteathy
  • 1
  • 2

1 Answers1

2

You have a couple options:

  1. Modify your Python programs so that when they receive signals like SIGTERM they propagate them to the children explicitly.

  2. Enable the supervisord options stopasgroup and killasgroup. These options are documented as sending signals to the entire process group rather than just one process.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • I have set the config options: `stopasgroup=true, killasgroup=true`.But it doesn't seem to work. – fanteathy May 05 '16 at 10:05
  • Can you check (using `ps -f` or so) what the Parent PID of each process is, and what the Process Group ID (PGID) of each process is? Knowing the full details would really help here. Also, can you try setting a signal handler in each Python program to print something on `SIGTERM`, and testing with `stopasgroup`? – John Zwinck May 05 '16 at 10:16
  • OK,I'll try, Thanks so much. – fanteathy May 05 '16 at 12:53