我正在嘗試創建一個程序,它接收包含UNIX命令列表的輸入文件並以特定順序執行這些命令。 我正在學習fork()
,wait()
,execvp()
系統調用,並且對等待和分岔模式有一些疑問。 這是我用於執行進程的結構。進程可以並行或按順序執行。我將在排序中決定這一點。 假設我必須按順序執行過程A,B,C D,E.使用fork執行UNIX命令,執行execvp
這裏是我爲此提出的結構。請讓我知道這是否正確。
ExecuteNodes function()
For loop {}from 0 to vector size // vector - this is the data structure that will have all the input file details
{
For loop {}// this is for my ordering logic. For all nodes I calculate the number of nodes that can execute paralley . Also using this loop to set the nodes ready for execution
For loop {
if that node is ready for execution.
run a loop for the number of concurrent processes for that node .
pid = fork()
if(pid == 0)
execvp();
}
}
for loop {all nodes}
{
wait()
}
這個結構是否正確?請讓我知道你的建議/意見。