Having trouble with fork(), pipe(), dup2() and exec() in C

后端 未结 6 655
时光取名叫无心
时光取名叫无心 2020-12-01 03:44

Here\'s my code:

#include 
#include 
#include 
#include 
#include 

#         


        
6条回答
  •  时光取名叫无心
    2020-12-01 04:40

    Jonathan has the right idea. You rely on the first process to fork all the others. Each one has to run to completion before the next one is forked.

    Instead, fork the processes in a loop like you are doing, but wait for them outside the inner loop, (at the bottom of the big loop for the shell prompt).

    loop //for prompt
        next prompt
        loop //to fork tasks, store the pids
            if pid == 0 run command
            else store the pid
        end loop
        loop // on pids
            wait
        end loop
    end loop
    

提交回复
热议问题