简体   繁体   中英

Process chain ending each other from last

I have a chain of process looking like this P0 (main process) creates P1, then P1 create P2, etc...

When Pn is created (n being a random number ~ 10), all process except P0 needs to be stopped by a SIGSTOP signal. When all of them are stopped, P0 has to printf("All process stopped"), then wake all of them with SIGCONT.

This much I've done easily, but here's the problem : When P(n) is wake up (by P(n-1)), all process (except P0) needs to be killed, then P0 printf("End of prog")

I can't use wait, waitpid. I've tried to make Pn send a signal to P0 then P0 send a SIGTERM signal to all process, but Pn will always end AFTER P0 and this is not good. I've also tried to make Pn kill P(n-1) and P(n-1) kills P(n-2), same problem.

Anyway has an idea to make sure all of process are killed when P9 prints the message? I'm using SIGCHLD for P0 to know when P1 is stopped (therefore P2, P3, ...). And I should be able to use it for this too, but how can I know if I get this signal in P0 because P1 is killed or resumed or stopped?

I found the solution, once all process have been stopped, I'm updating the action mask with SA_NOCLDSTOP | SA_NOCLDWAIT to make sure that once my SIGCHLD's handler will be called, it'll be because the child process is dead (and no zombies issues).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM