uptime -s changing reported time












0















I have a script that relies in time Ubuntu 18.04 is started found by:



uptime -s


I save that value in a file when I run the script. I noticed when I started Ubuntu that time was:



uptime -s
2019-01-07 18:01:59


After running for a bit more than two hours, same command reports now a different time (I remained logged in same account all this time):



uptime -s
2019-01-07 18:01:58


I would expect the command reports same time within same login session. But somehow time changes with 1 second (it is earlier now).



Is this an OS or tool issue?



https://elixir.bootlin.com/linux/latest/source/fs/proc/uptime.c
struct timespec64 uptime;
ktime_get_boottime_ts64(&uptime);


How can I get system up time without such fluctuation?



Update:



I though I found the answer in: Linux: Getting date & time of system startup



But I was wrong, it just luck, after running a few more tests, one can see it is OS problem, the time rotates between 58 and 59 depending on nanoseconds:



$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.670091767
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.627339874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.708332394
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.821526069
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.604129974
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.469767199
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.264900963
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.986611962
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.851955874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.958194732
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.066728481


I seems, there is no reliable system uptime to second level.










share|improve this question

























  • Possible duplicate of Linux: Getting date & time of system startup

    – bummi
    Jan 7 at 19:30
















0















I have a script that relies in time Ubuntu 18.04 is started found by:



uptime -s


I save that value in a file when I run the script. I noticed when I started Ubuntu that time was:



uptime -s
2019-01-07 18:01:59


After running for a bit more than two hours, same command reports now a different time (I remained logged in same account all this time):



uptime -s
2019-01-07 18:01:58


I would expect the command reports same time within same login session. But somehow time changes with 1 second (it is earlier now).



Is this an OS or tool issue?



https://elixir.bootlin.com/linux/latest/source/fs/proc/uptime.c
struct timespec64 uptime;
ktime_get_boottime_ts64(&uptime);


How can I get system up time without such fluctuation?



Update:



I though I found the answer in: Linux: Getting date & time of system startup



But I was wrong, it just luck, after running a few more tests, one can see it is OS problem, the time rotates between 58 and 59 depending on nanoseconds:



$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.670091767
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.627339874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.708332394
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.821526069
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.604129974
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.469767199
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.264900963
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.986611962
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.851955874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.958194732
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.066728481


I seems, there is no reliable system uptime to second level.










share|improve this question

























  • Possible duplicate of Linux: Getting date & time of system startup

    – bummi
    Jan 7 at 19:30














0












0








0








I have a script that relies in time Ubuntu 18.04 is started found by:



uptime -s


I save that value in a file when I run the script. I noticed when I started Ubuntu that time was:



uptime -s
2019-01-07 18:01:59


After running for a bit more than two hours, same command reports now a different time (I remained logged in same account all this time):



uptime -s
2019-01-07 18:01:58


I would expect the command reports same time within same login session. But somehow time changes with 1 second (it is earlier now).



Is this an OS or tool issue?



https://elixir.bootlin.com/linux/latest/source/fs/proc/uptime.c
struct timespec64 uptime;
ktime_get_boottime_ts64(&uptime);


How can I get system up time without such fluctuation?



Update:



I though I found the answer in: Linux: Getting date & time of system startup



But I was wrong, it just luck, after running a few more tests, one can see it is OS problem, the time rotates between 58 and 59 depending on nanoseconds:



$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.670091767
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.627339874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.708332394
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.821526069
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.604129974
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.469767199
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.264900963
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.986611962
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.851955874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.958194732
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.066728481


I seems, there is no reliable system uptime to second level.










share|improve this question
















I have a script that relies in time Ubuntu 18.04 is started found by:



uptime -s


I save that value in a file when I run the script. I noticed when I started Ubuntu that time was:



uptime -s
2019-01-07 18:01:59


After running for a bit more than two hours, same command reports now a different time (I remained logged in same account all this time):



uptime -s
2019-01-07 18:01:58


I would expect the command reports same time within same login session. But somehow time changes with 1 second (it is earlier now).



Is this an OS or tool issue?



https://elixir.bootlin.com/linux/latest/source/fs/proc/uptime.c
struct timespec64 uptime;
ktime_get_boottime_ts64(&uptime);


How can I get system up time without such fluctuation?



Update:



I though I found the answer in: Linux: Getting date & time of system startup



But I was wrong, it just luck, after running a few more tests, one can see it is OS problem, the time rotates between 58 and 59 depending on nanoseconds:



$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.670091767
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.627339874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.708332394
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.821526069
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.604129974
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.469767199
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.264900963
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.986611962
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.851955874
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:58.958194732
$ date -d "`cut -f1 -d. /proc/uptime` seconds ago" +"%F %T.%N"
2019-01-07 18:01:59.066728481


I seems, there is no reliable system uptime to second level.







linux ubuntu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 7 at 19:46







ppp

















asked Jan 7 at 19:21









pppppp

11




11













  • Possible duplicate of Linux: Getting date & time of system startup

    – bummi
    Jan 7 at 19:30



















  • Possible duplicate of Linux: Getting date & time of system startup

    – bummi
    Jan 7 at 19:30

















Possible duplicate of Linux: Getting date & time of system startup

– bummi
Jan 7 at 19:30





Possible duplicate of Linux: Getting date & time of system startup

– bummi
Jan 7 at 19:30










1 Answer
1






active

oldest

votes


















0














Found an answer here:



Linux: Getting date & time of system startup



This command seems to give correct result, unlike uptime -s



 date -d "`cut -f1 -d. /proc/uptime` seconds ago"


Example:



date -d "`cut -f1 -d. /proc/uptime` seconds ago"
Mo 7. Jan 18:01:59 CET 2019


It seems uptime -s is not reliable.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391618%2fuptime-s-changing-reported-time%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Found an answer here:



    Linux: Getting date & time of system startup



    This command seems to give correct result, unlike uptime -s



     date -d "`cut -f1 -d. /proc/uptime` seconds ago"


    Example:



    date -d "`cut -f1 -d. /proc/uptime` seconds ago"
    Mo 7. Jan 18:01:59 CET 2019


    It seems uptime -s is not reliable.






    share|improve this answer




























      0














      Found an answer here:



      Linux: Getting date & time of system startup



      This command seems to give correct result, unlike uptime -s



       date -d "`cut -f1 -d. /proc/uptime` seconds ago"


      Example:



      date -d "`cut -f1 -d. /proc/uptime` seconds ago"
      Mo 7. Jan 18:01:59 CET 2019


      It seems uptime -s is not reliable.






      share|improve this answer


























        0












        0








        0







        Found an answer here:



        Linux: Getting date & time of system startup



        This command seems to give correct result, unlike uptime -s



         date -d "`cut -f1 -d. /proc/uptime` seconds ago"


        Example:



        date -d "`cut -f1 -d. /proc/uptime` seconds ago"
        Mo 7. Jan 18:01:59 CET 2019


        It seems uptime -s is not reliable.






        share|improve this answer













        Found an answer here:



        Linux: Getting date & time of system startup



        This command seems to give correct result, unlike uptime -s



         date -d "`cut -f1 -d. /proc/uptime` seconds ago"


        Example:



        date -d "`cut -f1 -d. /proc/uptime` seconds ago"
        Mo 7. Jan 18:01:59 CET 2019


        It seems uptime -s is not reliable.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 19:27









        pppppp

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1391618%2fuptime-s-changing-reported-time%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy