Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello~
i'm finding how to get absolutely increasing count in AIX.

somebody help me. T_T

What I have tried:

I do not want the following cases.

C++
...
FILE *utmp = fopen(UTMP_FILE, "r");

   if (utmp == NULL) {
     /* Can't open utmp, use current time as boottime */
     boottime = time(NULL);
   } else {
     while (fread((char *) &buf, sizeof(buf), 1, utmp) == 1) {
        if (buf.ut_type == BOOT_TIME) {
            boottime = buf.ut_time;
            break;
        }
     }
   }
...


because if the system time is changed using a command such as "date"
the wrong value is obtained.
Posted
Updated 26-Feb-19 1:28am

If you are looking for a monotonic clock the do use a monotonic clock: IBM Knowledge Center - clock_getres, clock_gettime, and clock_settime Subroutine[^].
 
Share this answer
 
Comments
moooooong 26-Feb-19 19:31pm    
Thanks to that, I was able to solve it well. :)
CPallini 27-Feb-19 3:13am    
You are welcome.
Pretty much, you can't. Think about it: ignore computers for a moment.
You are sat in your car, your mobile is at home, you don't wear a watch.
What time is it?
You have the clock in your car - but is that right? did you adjust it for daylight savings time? Did you adjust it the right way?
You can't tell, unless you use some reliable external time source - in this case, you can turn on the radio and find a station that will tell you. You can then check that against your car clock and decide if it's right or not. But if the radio is broken? You have only the clock to go on and you cannot tell at all if it's right.

Back to your problem, and you have the same thing: unless you have access to the internet and an external time source, you have only got the system clock to work with and that can be changed at will (because Windows can't access an external clock unless it's connected to the internet!)

At a guess, you are trying to prevent users from "rewinding time" and staying inside a "trial period" - but about the only thing you can do it record the last date & time at which your app was running, and compare the system time to that to try and spot teh cheats. Unless you have access to external time sources, you can't do much else...
 
Share this answer
 
Comments
moooooong 26-Feb-19 6:19am    
Thank you for answer.
however, On Linux, I have confirmed that the count of boot time is recorded as a result of the "/proc/uptime" file.
This counts regardless of whether the system time is changed.
So I want to know if there is a value that is absolutely counted on AIX.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900