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++)

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

9 Years
Discussion Span
Last Post by peaceful_soul

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.