Time change interrupt

This is a discussion on Time change interrupt within the Linux Programming forums, part of the Platform Specific Boards category; Is there any signal or interrupt available in Linux which interrupt my process or application when system time is changed ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22

    Time change interrupt

    Is there any signal or interrupt available in Linux which interrupt my process or application when system time is changed manually by any user or any NTP Client?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I'm not aware of such a thing.

    I had a quick look through sys_settimeofday() and there doesn't look like there is anything there.

    Have you had a look at what cron does to find out if it's doing anything about it?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22
    cron is check the task for execution on every one minute if the time is changed it doesn't care about it,it only run the task whose time is match by the cron.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by vipul_vgp View Post
    cron is check the task for execution on every one minute if the time is changed it doesn't care about it,it only run the task whose time is match by the cron.
    So, why are you trying to solve a problem that cron isn't solving? After all, if it was a problem in cron, then it would probably have been fixed in the last 30+ years it's been around.

    After all (large) chanes in time are not that common, and only the root user can change the time - and root can also do all sorts of other bad things that would cause your cron application to fail.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22
    the problem is not cron, the problem is my application is like cron but not exactly cron, it determine feature time of job to execute. is time is change it will miss behave and i have to restart my application therefor i want one signal or interrupt on time change so my application could rearrange the list of job and start to execute again.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by vipul_vgp View Post
    the problem is not cron, the problem is my application is like cron but not exactly cron, it determine feature time of job to execute. is time is change it will miss behave and i have to restart my application therefor i want one signal or interrupt on time change so my application could rearrange the list of job and start to execute again.
    And I say that Linux doesn't have such a feature. Did the suggestion I made the other day not work?

    As an alternative, perhaps you can detect when things have gone wrong, and do something about the fact - e.g. if you know that a process is about to start in 16 seconds, and you wait for 16 seconds, check that the current time is 16 seconds [give or take] from the time you started waiting.

    --
    Mats
    Last edited by matsp; 02-25-2009 at 03:51 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Location
    India, Gujarat
    Posts
    22
    no it is not work perfectly, ok thanks

    i think my ntp client can solve this problem,

    when ntp client set the time then it will signal to my application for rearrange list.
    Last edited by vipul_vgp; 02-25-2009 at 03:52 AM.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by vipul_vgp View Post
    no it is not work perfectly,
    Ok, describe what is going wrong and why. Also see my edit to previous post.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,263
    Configure a SIGALRM to go off each minute. When it goes off check the system time. If it is different from the last time by some value other than a minute (approximately), you know the system time has been changed.

    Be aware that many system change the time slowly -- for instance if you move time ahead by one hour, it does not immediately change, but the ticking of seconds is "speeded up" so that over some short period of time the clock will adjust.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by brewbuck View Post
    Configure a SIGALRM to go off each minute. When it goes off check the system time. If it is different from the last time by some value other than a minute (approximately), you know the system time has been changed.
    I suggested a similar method. I don't know why, but OP seems to think it's not working.

    Be aware that many system change the time slowly -- for instance if you move time ahead by one hour, it does not immediately change, but the ticking of seconds is "speeded up" so that over some short period of time the clock will adjust.
    This is CERTAINLY the case in systems running on virtual machines, particularly if the system is stopped and started (e.g. paused or migrated).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 04:41 AM
  2. What is the best way to record a process execution time?
    By hanash in forum Linux Programming
    Replies: 7
    Last Post: 03-15-2006, 07:17 AM
  3. help with calculating change from a dollar
    By z.tron in forum C++ Programming
    Replies: 3
    Last Post: 09-13-2002, 04:58 PM
  4. relating date....
    By Prakash in forum C Programming
    Replies: 3
    Last Post: 09-19-2001, 10:08 AM
  5. Replies: 2
    Last Post: 09-04-2001, 03:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21