我正在尝试创建一个程序,它接收包含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()
}
这个结构是否正确?请让我知道你的建议/意见。