i wrote a program called trivial.c that takes an integer "time" from the command line and does nothing but loop for 5 times and sleep for "time" seconds in each iteration. the loop looks something like this :

for(i=0; i<5; i++)
{
sleep(time);
}

then a file trivial.data that contains the following information
trivial 5
trivial 10
trivial 2
trivial 6

i want to write a program RunAnotherProcess.c that can have up 3 children that will run the trivial.data ( i can use redirection so a sample run would be :
RunAnotherProcess < trivial.data

how can i read from the file trivial.data and pass it to the child ( the one that i fork in the RunAnotherProcess) to execute it ?

i googled and i thing that i should use fget( ) and execvp ( ) . but the thing is i dont know how to use these (though i tried a lot )

can you please help me ?

thank you in advance

Recommended Answers

All 2 Replies

Look into fork().

Dear friends

i happened to have the same problem as that of wonder_laptop i couldnt solve it.


i used fork to create a child process but i didnt know how to take the line from the command line (which is trivial.data in this case) and make the child execute this process.


can you please help?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.