I have a requirement to start my application at certain time. I don’t want to be put in the corn job. My executable is an application and like to start on 2011-Jan-20
So I have to run it as
./app –date 2011-Jan-20
Here problem is, how I will calculates the time difference from current and date supplied in command line option.
I don’t want to write won function. Is there any in build function are available for such type of time difference. ( c and Linux)
You can calculate the difference between the start time and now in milliseconds and then wait for that many milliseconds by passing that number as a timeout argument to
select()orepoll().To calculate the difference, one way is to first convert your date string to
struct tmusingstrptime()and then pass it tomktime()which is going to give you a number of seconds since unix epoch 1970-01-01 00:00:00. Then get the current time by usinggettimeofday()orclock_gettime(), they also report time passed since unix epoch. Convert the start time and the current time to seconds and subtract the values.