I am trying to create a program that takes in an input file containing a list of UNIX commands and executes these commands in a particular order.
I am learning fork(), wait(), execvp() system calls and had some questions about the wait and forking pattern.
This is the structure I am using for executing processes. Processes can execute in parallel or sequentially. I will be deciding this in the ordering.
Say I have to execute processes in the order A, B, C D, E.
Here is the structure I came up with for this. Please let me know if this is correct.
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()
}
Is this structure correct ? Please let me know your suggestions/comments.