简体   繁体   English

流程链从最后开始彼此结束

[英]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... 我有一个看起来像这样的流程链:P0(主流程)创建P1,然后P1创建P2,依此类推...

When Pn is created (n being a random number ~ 10), all process except P0 needs to be stopped by a SIGSTOP signal. 当创建Pn时(n是一个随机数〜10),除P0外的所有进程都需要通过SIGSTOP信号停止。 When all of them are stopped, P0 has to printf("All process stopped"), then wake all of them with SIGCONT. 当所有它们都停止时,P0必须先进行printf(“所有进程已停止”),然后使用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") 我已经轻松完成了很多操作,但这是问题所在:当P(n)唤醒(由P(n-1)唤醒)时,所有进程(P0除外)都需要终止,然后P0 printf(“ prog Prog ”)

I can't use wait, waitpid. 我不能使用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. 我试图使Pn向P0发送信号,然后P0向所有进程发送SIGTERM信号,但是Pn总是在P0之后结束。 I've also tried to make Pn kill P(n-1) and P(n-1) kills P(n-2), same problem. 我也试图使Pn杀死P(n-1)和P(n-1)杀死P(n-2),这是同样的问题。

Anyway has an idea to make sure all of process are killed when P9 prints the message? 无论如何,有一个想法可以确保在P9打印消息时杀死所有进程? I'm using SIGCHLD for P0 to know when P1 is stopped (therefore P2, P3, ...). 我将SIGCHLD用于P0,以了解何时停止了P1(因此停止了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? 我也应该可以将其用于此目的,但是如何知道我是否在P0中收到此信号,因为P1被杀死,恢复或停止了?

I found the solution, once all process have been stopped, I'm updating the action mask with SA_NOCLDSTOP | 我找到了解决方案,一旦所有进程都停止了,我将使用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). SA_NOCLDWAIT确保一旦调用我的SIGCHLD的处理程序,这将是因为子进程已死(并且没有僵尸问题)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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