954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

using a process to run another one

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

wonder_laptop
Junior Poster in Training
89 posts since Aug 2007
Reputation Points: 25
Solved Threads: 0
 

Look into fork().

plgriffith
Junior Poster
100 posts since Feb 2008
Reputation Points: 10
Solved Threads: 6
 

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?

peaceful_soul
Newbie Poster
12 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You