running a program for a specified time

how can i run a program for a specified time?
i need to print a current time during program execution.

hi

1) for the second question
with the following tm structure in time.h u can get the current time

time_t curr = time(NULL);
struct tm *tom = localtime(&curr);

Current Year: tom->tm_year+1900,
current month: tom->tm_mon+1
Current Day: tom->tm_mday
Current Hour: tom->tm_hour
Current Minute: tom->tm_min
Current Second: tom->tm_sec

2) for the first question
using the above structure get the values at the beginning of program
and at intervals check for the time value accordingly
proceed or exit the program

hope this helps.

Do you mean start the program at a certain time, ie., start it at 11:45?
Try man cron and man at.

If you mean run it for 1500ms then look into gettimeofday()

Thanks. Your advice is very helpful.