Is there a good way to alter execution order of child processes created with fork()?

前端 未结 1 1970
礼貌的吻别
礼貌的吻别 2020-12-11 11:49

I am looking for creating child processes for which I can control their order of processing.

Simple example:

  • Parent creates 2 children with fork
相关标签:
1条回答
  • 2020-12-11 12:30

    You need to use actual inter-process communication to achieve this.

    You seem to think that the waitpid() function has something to do with waiting for a process to print output, but that's not at all what it does.

    Create a semaphore in the parent, pass it to both children, and have one child wait on the semaphore before printing and the other one messaging the semaphore after it's done printing.

    0 讨论(0)
提交回复
热议问题