views:

57

answers:

3

I'm working in linux. I have two programs that run for infinite time ( that is , wont stop unless i kill the process ).i want to run program 1 first and then run program 2 after 20 seconds ( both will have to run simultaneously as one reads a file written by the other ).Currently , i am running the 2 programs by manually keeping track of time.. Is there a way to automate this ? i.e. is there any command or can any program be written to do this..

+1  A: 
prog1 &
sleep 20
prog2
Anon.
the 2 programs are : first_auto.c and after 20 seconds , prime_auto.chow do i compile and run.. can you please explain..
trinity
@trinity: That's a different question. Please ask a new question.
Greg D
If you don't know how to compile your programs, that's something you should research first.
Tyler McHenry
Huh! trinity - the trinity that hacked the IRS database....quote from the Matrix....
tommieb75
@Greg and @Tyler : till then i thought i had to use ./a.out for both programs and hence the doubt.. Now i found out i could save the out files using the -o option.@Anon : Thanks a lot
trinity
@trinity: You also have the option to rename them via `mv`.
Greg D
A: 

Using the shell:

$ program1 & sleep 20 ; program2

Gnurou
hey thanks , it worked .
trinity
A: 

If one program reads from the file output by the other you should consider using a pipe to pass output from one to the input of the other:

$> program1 | program2

I'm assuming that you have control over these two programs and can get them to write to stdout and read from stdin.

Tom Duckering
Actually , i maintain a circular buffer of files - f1 , f2 , f3.. and the first program writes into these files , switching between them every 20 seconds. And the reader program also reads from these. I have written the code to do this and it works fine..
trinity