System duration acquisition method and device and storage medium

By using the process communication mechanism and system time offset configuration file in the operating system, the operating system's usage time is solved, and the problem of poor time calculation accuracy and timeliness in the prior art is achieved, and accurate time acquisition is achieved in various situations.

CN119646769APending Publication Date: 2025-03-18KYLIN CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411680290.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-22
Publication Date
2025-03-18

AI Technical Summary

Technical Problem

In the prior art, the accuracy and timeliness of calculating operating systems are poor, especially when the user modifys the system time or disconnects the network connection, the system time cannot be accurately obtained.

Method used

By using the process communication mechanism to receive the system usage time query request, the system time offset configuration file is read, which is generated during system installation, and records the system time offset and network time protocol time offset. Based on these offsets and the current system time, the system duration is calculated.

Benefits of technology

It realizes that when users modify the system time or disconnect the network, they can still accurately calculate the system usage time, improve the calculation accuracy and timely rate of the system duration, and prevent illegally extending the operating system service life.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119646769A_ABST
    Figure CN119646769A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a system time length obtaining method and device and a storage medium, and the method comprises the steps: receiving a system use time length query request, reading a system time offset configuration file through a process communication mechanism, generating the system time offset configuration file when a system is installed, and storing the system time offset configuration file in the process communication mechanism; recording a system time offset and a network time protocol time offset, wherein the system time offset is updated along with the system time modification event; reading the current system time; reading the system time offset and the network time protocol time offset from the system time offset configuration file, and determining the system duration according to the network time protocol time offset, the system time offset and the current system time. The system time offset and the network time protocol time offset can be used for monitoring the system time change in real time, and the final calculation result is not influenced when the user interrupts the network and modifies the system time in the process of actually using the operating system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of system duration, and in particular to a method, device and storage medium for obtaining system duration. Background Art

[0002] The business model of domestic operating systems mainly includes commercial technical support, professional version payment, customized systems, etc. Among them, professional versions or customized specific software services usually have corresponding trial versions of the system. Usually, the trial version of the operating system will open certain advanced customization functions during the installation trial period, and these functions will be closed after the trial period. The determination of whether the operating system is within the trial period has become a key condition for turning on and off certain paid services or functions, that is, real-time monitoring of whether the operating system usage time is within the agreed trial time range, and turning on and off certain restricted services or functions in the operating system accordingly.

[0003] Currently, the operating system usage time can be calculated by obtaining the current time and the system installation time and calculating the difference between them. The current time usually comes from the system time or the network time. If it is directly obtained from the system time, the correct result will be affected after the user modifies the system time; if the current time is obtained from the network time, the correct result cannot be obtained if the user disconnects from the network. Even if the network connection is normal, obtaining the network time will require an uncertain delay depending on the network conditions, and the correct result may not be returned in time. Summary of the invention

[0004] The embodiments of the present invention provide a system duration acquisition method, device and storage medium to solve the technical problem of poor accuracy and timeliness in calculating the usage duration of an operating system in the prior art.

[0005] In a first aspect, an embodiment of the present invention provides a method for obtaining system duration, including:

[0006] Utilize the process communication mechanism to receive the system usage time query request, read the system time offset configuration file, the system time offset configuration file is generated when the system is installed, and records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event;

[0007] Read the current system time;

[0008] The system time offset and the network time protocol time offset are read from the system time offset configuration file, and the system duration is determined according to the network time protocol time offset and the system time offset and the current system time.

[0009] In a second aspect, an embodiment of the present invention further provides a system duration acquisition device, including:

[0010] A receiving module receives a system usage time query request by using a process communication mechanism, reads a system time offset configuration file, the system time offset configuration file is generated when the system is installed, records the system time offset and the network time protocol time offset, and the system time offset is updated with a system time modification event;

[0011] Reading module, used to read the current system time;

[0012] The determination module is used to read the system time offset and the network time protocol time offset from the system time offset configuration file, and determine the system duration according to the network time protocol time offset and the system time offset and the current system time.

[0013] In a third aspect, an embodiment of the present invention further provides a storage medium comprising computer executable instructions, which, when executed by a computer processor, are used to execute the system duration acquisition method provided in the above embodiment.

[0014] The system duration acquisition method, device and storage medium provided by the embodiment of the present invention receive a system usage duration query request by utilizing a process communication mechanism, read a system time offset configuration file, the system time offset configuration file is generated when the system is installed, records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event; read the current system time; read the system time offset and the network time protocol time offset from the system time offset configuration file, and determine the system duration according to the network time protocol time offset and the system time offset and the current system time. The system time change can be monitored in real time by utilizing a time-related system call, and the new system time offset and the network time protocol time offset are calculated and recorded at the same time. The user disconnects from the network and modifies the system time during the actual use of the operating system, and the final calculation result is not affected, that is, the user cannot illegally extend the service life of the specified service of the operating system by disconnecting from the network and modifying the system time. At the same time, there is no need for network intervention, and the system usage duration can be calculated relatively accurately and quickly. The calculation accuracy and timeliness of the system duration are improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0016] Figure 1 1 is a flow chart of a method for obtaining system duration provided in Embodiment 1 of the present invention;

[0017] Figure 2 is a flowchart of a method for obtaining system duration provided in Embodiment 2 of the present invention;

[0018] Figure 3 It is a structural diagram of a system duration acquisition device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION

[0019] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0020] Embodiment 1

[0021] Figure 1 : is a flow chart of a method for obtaining system duration provided in Embodiment 1 of the present invention. This embodiment is applicable to the case of obtaining the usage duration of an applicable version of the system. The method can be executed by a system duration obtaining device, and specifically includes the following steps:

[0022] Step 110, using the process communication mechanism to receive a system usage time query request, read the system time offset configuration file, the system time offset configuration file is generated when the system is installed, records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event.

[0023] In the applicable version of the system, the user can obtain the current system usage time by actively querying, or can also obtain the current system usage time at a fixed time, and display the obtained results so that the user can timely understand the current system usage time. In this embodiment, the above two methods can be used as system usage time query requests. The user can use the inter-process communication mechanism, such as the dbus service, to directly send a request to obtain the system usage time or a signal to register the change of system usage time to the main process. When the main process receives the request, it reads the system time offset configuration file. The system time offset configuration file is automatically created and generated when the system is installed, wherein the system time offset and the network time protocol time offset can be recorded in the system time offset configuration file, wherein the system time offset is updated with the system time modification event.

[0024] Exemplarily, the reading of the system time offset configuration file may include: determining the system time offset configuration file according to the set storage path and file name, and reading the string content in the configuration file; creating at least two variables of the GKeyFile type; decoding the string through Base64 encoding; loading the decoding result as data into the GKeyFile variable, and specifying the group name and key name, and obtaining the corresponding variable value through the GKeyFile data read interface.

[0025] The storage path and file name set during system installation are used to search for the system time offset configuration file, and the string content in the file is read. Corresponding variables are created for recording the corresponding results. The string is decoded using the set encoding method, and the result is written into the GKeyFile variable created above, and the corresponding variable value is read accordingly. In this way, the content of the system time offset configuration file can be protected by a layer of encoding, so that the user cannot affect the program calculation results by directly modifying the configuration file. This prevents the problem of system duration calculation errors caused by tampering with the file content.

[0026] Step 120, read the current system time.

[0027] The system time refers to the time recorded in the current system, which may be modified or unmodified, and may be the system time that has been synchronized through the network before or may not be synchronized.

[0028] Step 130, reading the system time offset and the network time protocol time offset from the system time offset configuration file, and determining the system duration according to the network time protocol time offset and the system time offset and the current system time.

[0029] In this embodiment, the hardware time dimension when the operating system is installed is used as the standard, and the subsequent ntp time offset and the local system time offset are monitored and recorded regularly. Finally, the time value under the hardware time dimension when the operating system is installed is calculated according to the system time and the corresponding offset, and the difference between the writing time of the kernel file in the operating system is the usage time of the current operating system. The local system time offset is recorded regularly, and the offset time is corrected by ntp time to obtain the original system time of the operating system. Finally, the difference between the corrected system time and the system installation time is calculated to obtain the actual usage time of the system.

[0030] Exemplarily, determining the system duration based on the network time protocol time offset, the system time offset, and the current system time may include: calculating the difference between the current system time and the system time offset to obtain a system time correction value; obtaining the system installation time based on the kernel file creation time first recorded when the system is installed; and calculating the system duration based on the system time correction value and the system installation time. That is, the current system time T-system time offset offset is calculated to obtain the corrected system time N (in the same time dimension as when the operating system is installed). Calculate NI to obtain the usage time of the current operating system. Wherein I is the system installation time, which can be obtained by reading the creation time of the file / etc / .InstallTime or / boot / initrd.img-KV".

[0031] This embodiment receives a system usage time query request by using a process communication mechanism, reads a system time offset configuration file, the system time offset configuration file is generated when the system is installed, records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event; reads the current system time; reads the system time offset and the network time protocol time offset from the system time offset configuration file, and determines the system duration according to the network time protocol time offset and the system time offset and the current system time. The system time change can be monitored in real time by using a time-related system call, and the new system time offset and the network time protocol time offset are calculated and recorded at the same time. The user disconnects from the network and modifies the system time during the actual use of the operating system, and the final calculation result is not affected, that is, the user cannot illegally extend the service life of the specified service of the operating system by disconnecting from the network and modifying the system time. At the same time, there is no need for network intervention, and the system usage duration can be calculated more accurately and quickly. The calculation accuracy and timeliness of the system duration are improved.

[0032] In a preferred implementation of this embodiment, the method may further add the following steps: when the system is installed, the system time offset configuration file is created, and the system time offset and the network time protocol time offset are set to 0. The system time offset configuration file is initialized in the above manner, and the system time offset and the network time protocol time offset therein are initialized and set, so as to facilitate the subsequent update of the two, and thus improve the accuracy of calculating the system usage time.

[0033] Embodiment 2

[0034] Figure 2It is a flow chart of the system duration acquisition method provided in the second embodiment of the present invention. This embodiment is optimized based on the above embodiment, and the method can also add the following steps: each time the system starts, a first thread is generated using the system time offset configuration file, and the first thread is used to update and maintain the system time offset configuration file. The first thread includes: a first timer and a second timer.

[0035] See also Figure 2 , the system duration acquisition method comprises:

[0036] Step 210: Generate a first thread using the system time offset configuration file each time the system is started. The first thread is used to update and maintain the system time offset configuration file. The first thread includes a first timer and a second timer.

[0037] In this embodiment, a service that starts automatically when the system is turned on will be created in the system. During the system startup process, the background main process will be run all the time. Three threads will be created in the main process: Thread 1 is responsible for recording the system time T regularly (such as once every minute, and the regular time interval can be modified), obtaining the ntp time N once every ten minutes through the ntp protocol, and then comparing the ntp time offset with the monitored time offset, and adjusting each other. Optionally, the first thread uses the first timer to perform the following operations in a loop according to the first preset duration: obtain the current network time protocol time ntp_time; read the network time protocol time offset in the system time offset configuration file and calculate the network time protocol calibration time; obtain the current local system time, read the system time offset in the system time offset configuration file and calculate the local system calibration time; calculate the difference based on the network time protocol calibration time and the local system calibration time; adjust the system time offset or the network time protocol time offset according to the difference.

[0038] The adjusting of the system time offset or the network time protocol time offset according to the difference may include: if the calculated difference is less than 24 hours and the current system time offset is not 0, adjusting the system time offset based on the network time protocol calibration time and storing it in the system time offset configuration file; if the calculated difference is greater than or equal to 24 hours or the current system time offset is 0, adjusting the network time protocol time offset based on the current local system calibration time and storing it in the system time offset configuration file.

[0039] In addition, the first thread is also used to start the second timer; the first thread uses the second timer to perform the following operations in a loop according to the second preset duration: based on obtaining the current system time and the timer periodically updating the system duration variable; the second thread monitors the system time changes in real time, and performs the following operations each time the time change is monitored: obtaining the modified system time, and calculating the time offset based on the modified system time and the timer periodically updating the system duration; accumulating the calculated time offset with the system time offset recorded in the system time offset configuration file, and writing the calculated result back to the system time offset configuration file as the new system time offset; updating the timer periodically updating the system duration value; calling the first thread to adjust the system time offset or the network time protocol time offset.

[0040] Exemplarily, two timing operations are started in the first thread, which are executed once every one minute and once every ten minutes respectively.

[0041] Timer 1 obtains the current ntp time: ntp_time. Read the system time offset (offset) and ntp time offset (ntp_offset) in the configuration file. Calculate the ntp calibration time: ntp_time-ntp_offset (ntp_offset is zero before the first execution of the service, otherwise ntp_offset is the difference between the calibrated local time and the ntp time after the first successful acquisition of the ntp time). Calculate the local system calibration time: timep-offset (after the operating system is installed, the offset is 0 before the system time is modified). Calculate the difference between the ntp calibration time and the local system calibration time: When the network is continuously unobstructed, the ntp calibration time is more accurate than the local system calibration time, because the local calibration time will have a larger error as the number of times the user modifies the time increases (each time the user modifies the system time, the calibration time will have an error between [0,60] seconds). If the calculated difference is less than 24 hours and the current system time offset is not 0 (that is, the system time has been changed after the operating system was installed), the system time offset offset is adjusted based on the ntp calibration time and stored in the system time offset configuration file. Correspondingly, if the calculated difference is greater than or equal to 24 hours or the current system time offset is 0 (that is, the system time has never been changed after the operating system was installed and is still in the hardware time dimension when the system was installed), the ntp time offset ntp_offset is adjusted based on the current local system calibration time and stored in the system time offset configuration file.

[0042] The first thread uses the second timer to perform the following loop operation: obtaining the current system time, and using the current system time to record the system time when the second timer is executed next time.

[0043] That is, get the current system time timep, and record the system time next_time when timer 2 is executed next time as timep+60.

[0044] Step 220, using the process communication mechanism to receive the system usage time query request, read the system time offset configuration file, the system time offset configuration file is generated when the system is installed, records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event.

[0045] Step 230, read the current system time.

[0046] Step 240: read the system time offset and the network time protocol time offset from the system time offset configuration file, and determine the system duration according to the network time protocol time offset and the system time offset and the current system time.

[0047] This embodiment adds the following steps: each time the system starts, a first thread is generated using the system time offset configuration file, the first thread is used to update and maintain the system time offset configuration file, and the first thread includes: a first timer and a second timer. Responsible for regularly recording the system time, obtaining the NTP time once every cycle through the NTP protocol, and then comparing the NTP time offset with the monitored time offset, and adjusting each other. It can regularly record the local system time offset, and obtain the original system time of the operating system by correcting the offset time through the NTP time, and finally obtain the actual usage time of the system by calculating the difference between the corrected system time and the system installation time.

[0048] In a preferred implementation of this embodiment, the method can also add the following steps: generate a second thread using the system time offset configuration file, the second thread is used to monitor the changes of the system time, and modify the time offset for the modified system time and store it in the system time offset configuration file; the second thread uses the second timer to perform the following operations according to the second preset duration: obtain the predicted current system time after the second timer is executed according to the second preset duration, that is, the predicted system time before modification; obtain the modified system time, and calculate the time offset according to the modified system time and the timer to regularly update the system duration; add the calculated time offset to the system time offset recorded in the system time offset configuration file, and write the calculation result back to the system time offset configuration file as the new system time offset; update the timer to regularly update the system duration value; call the first thread to adjust the system time offset or the network time protocol time offset. The second thread can be used to monitor the changes of the system time, obtain the new system time E each time the system time is modified, and store the accumulated time offset (ET) in the configuration file. It can monitor the changes of system time in real time, and maintain the offset of system time and ntp time at the same time, so that no matter whether the user is connected to the Internet or not, and whether the local system time is modified multiple times, a relatively accurate system time can be obtained.

[0049] In another preferred implementation of this embodiment, the method can also add the following steps: using the system time offset configuration file to generate a third thread, the third thread is used to receive a system usage time query request in real time; using the third thread to perform the following operations: connecting and setting the callback function of the dbus interface get-usedtime; calling the interface get-usedtime callback function to calculate the current usage time of the operating system, and calculate the current time difference from the system's full-day usage; after the full-day usage time difference, executing to send a message to the dbus client, the message carries the variable system's full-day usage time, and sets a timer to send a message to the dbus client in a cycle with the third preset time as a period. The system usage time can be calculated regularly and sent to the client, and an interface is provided so that the dbus client can call the interface to obtain the system usage time. It is convenient for users to grasp the effective time of the system.

[0050] Embodiment 3

[0051] Figure 3 is a schematic diagram of the structure of the system duration acquisition device provided in the third embodiment of the present invention, see Figure 3 , the system duration acquisition device comprises:

[0052] The receiving module 310 is used to receive a system usage time query request, read a system time offset configuration file, the system time offset configuration file is generated when the system is installed, and records the system time offset and the network time protocol time offset. The system time offset is updated with the system time modification event;

[0053] The reading module 320 is used to read the current system time;

[0054] The determination module 330 is used to read the system time offset and the network time protocol time offset from the system time offset configuration file, and determine the system duration according to the network time protocol time offset and the system time offset and the current system time.

[0055] The system duration acquisition device provided in this embodiment receives a system usage duration query request and uses a process communication mechanism to read a system time offset configuration file, wherein the system time offset configuration file is generated when the system is installed, and records the system time offset and the network time protocol time offset, and the system time offset is updated with the system time modification event; reads the current system time; reads the system time offset and the network time protocol time offset from the system time offset configuration file, and determines the system duration according to the network time protocol time offset and the system time offset, and the current system time. When the user disconnects from the network and modifies the system time during the actual use of the operating system, it does not affect the final calculation result, that is, the user cannot illegally extend the use period of the specified service of the operating system by disconnecting from the network and modifying the system time. At the same time, there is no need for network intervention, and the system usage duration can be calculated more accurately and quickly. The calculation accuracy and timeliness of the system duration are improved.

[0056] Based on the above embodiments, the determining module includes:

[0057] A first calculation unit, used for calculating the difference between the current system time and the system time offset to obtain a system time correction value;

[0058] A second calculation unit is used to obtain the system installation time according to the kernel installation time recorded for the first time;

[0059] The third calculation unit is used to calculate the system duration according to the system time correction value and the system installation time.

[0060] Based on the above embodiments, the device further includes:

[0061] The creation module is used to create the system time offset configuration file when the system is installed, and set the system time offset and the network time protocol time offset to 0.

[0062] Based on the above embodiments, the device further includes:

[0063] A first thread generation module is used to generate a first thread using the system time offset configuration file each time the system is started, the first thread is used to update and maintain the system time offset configuration file, and the first thread includes: a first timer and a second timer;

[0064] The first thread uses the first timer to cyclically perform the following operations according to the first preset duration:

[0065] Get the current network time protocol time ntp_time;

[0066] Reading the system time offset and the network time protocol time offset in the system time offset configuration file to calculate the network time protocol calibration time, and calculating the local system calibration time;

[0067] Calculating a difference based on the network time protocol calibration time and the local system calibration time;

[0068] Adjusting a system time offset or a network time protocol time offset according to the difference;

[0069] The first thread uses the second timer to perform the following loop operation:

[0070] The current system time is obtained, and the system time when the second timer is executed is recorded using the current system time.

[0071] Based on the above embodiments, adjusting the system time offset or the network time protocol time offset according to the difference includes:

[0072] If the calculated difference is less than 24 hours and the current system time offset is not 0, the system time offset is adjusted based on the network time protocol calibration time and stored in the system time offset configuration file;

[0073] If the calculated difference is greater than or equal to 24 hours or the current system time offset is 0, the network time protocol time offset is adjusted based on the current local system calibration time and stored in the system time offset configuration file.

[0074] Based on the above embodiments, the device further includes:

[0075] A second thread generation module, used to generate a second thread using the system time offset configuration file, wherein the second thread is used to monitor changes in the system time, and to modify the time offset according to the modified system time and store it in the system time offset configuration file;

[0076] The second thread performs the following operations after detecting the system time change:

[0077] Obtain the system time before modification according to the result of the second timer's cyclic execution according to the second preset duration;

[0078] Get the modified system time, and calculate the time offset based on the modified system time and the timer to regularly update the system duration;

[0079] Accumulate the calculated time offset and the system time offset recorded in the system time offset configuration file, and write the calculation result back to the system time offset configuration file as a new system time offset;

[0080] Update the timer to regularly update the system duration value;

[0081] The first thread is called to adjust the system time offset or the network time protocol time offset.

[0082] Based on the above embodiments, the device further includes:

[0083] A third thread generation module, used to generate a third thread using the system time offset configuration file each time the system is started, wherein the third thread is used to periodically receive a system usage time query request;

[0084] The third thread is used to perform the following operations:

[0085] Connect and set the callback function of dbus interface get-usedtime;

[0086] Call the get-usedtime callback function to calculate the current usage time of the operating system and the time difference between the current time and the system's full-day usage time.

[0087] After using the time difference for a whole day, a message is sent to the dbus client, the message carries the variable system usage time for a whole day, and a timer is set to cyclically send messages to the dbus client with a third preset time as a period.

[0088] Based on the above embodiments, the receiving module includes:

[0089] A determination unit, used to determine a system time offset configuration file according to a set storage path and file name, and read the string content in the configuration file;

[0090] A creation unit is used to create at least two variables of GKeyFile type;

[0091] A decoding unit, the apartment decodes the string through Base64 encoding;

[0092] The acquisition unit is used to load the decoding result as data into the GKeyFile variable, specify the group name and key name, and obtain the corresponding variable value through the GKeyFile data reading interface.

[0093] The system duration acquisition device provided in the embodiment of the present invention can execute the system duration acquisition method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0094] Embodiment 4

[0095] Embodiment 4 of the present invention further provides a storage medium comprising computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are used to execute the system duration acquisition method as described in any one of the above embodiments.

[0096] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0097] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0098] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0099] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0100] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for obtaining system duration, characterized in that: include: Receive a system usage time query request, and use a process communication mechanism to read a system time offset configuration file, wherein the system time offset configuration file is generated when the system is installed, and records the system time offset and the network time protocol time offset, and the system time offset is updated with a system time modification event; Read the current system time; The system time offset and the network time protocol time offset are read from the system time offset configuration file, and the system duration is determined according to the network time protocol time offset and the system time offset and the current system time.

2. The method according to claim 1, characterized in that Determining the system duration according to the network time protocol time offset, the system time offset, and the current system time includes: Calculate the difference between the current system time and the system time offset to obtain a system time correction value; The system installation time is obtained according to the kernel file creation time recorded for the first time when the system is installed; The system duration is calculated according to the system time correction value and the system installation time.

3. The method according to claim 1, characterized in that The method further comprises: When the system is installed, the system time offset configuration file is created, and the system time offset and the network time protocol time offset are set to 0.

4. The method according to claim 3, characterized in that The method further comprises: generating a first thread using the system time offset configuration file each time the system is started, the first thread being used to update and maintain the system time offset configuration file, the first thread comprising: a first timer and a second timer; The first thread uses the first timer to cyclically perform the following operations according to the first preset duration: Get the current network time protocol time ntp_time; Reading the system time offset and the network time protocol time offset in the system time offset configuration file to calculate the network time protocol calibration time, and calculating the local system calibration time; Calculating a difference based on the network time protocol calibration time and the local system calibration time; Adjusting a system time offset or a network time protocol time offset according to the difference; The first thread uses the second timer to perform the following loop operation: The current system time is obtained, and the system time when the second timer is executed is recorded using the current system time.

5. The method according to claim 3, characterized in that: The adjusting the system time offset or the network time protocol time offset according to the difference includes: If the calculated difference is less than 24 hours and the current system time offset is not 0, the system time offset is adjusted based on the network time protocol calibration time and stored in the system time offset configuration file; If the calculated difference is greater than or equal to 24 hours or the current system time offset is 0, the network time protocol time offset is adjusted based on the current local system calibration time and stored in the system time offset configuration file.

6. The method according to claim 5, characterized in that Generate a second thread using the system time offset configuration file, the second thread is used to monitor changes in system time, and modify the time offset according to the modified system time and store it in the system time offset configuration file; The second thread performs the following operations after detecting the system time change: The predicted current system time is obtained after the second timer is cyclically executed according to the second preset time length, that is, the predicted system time before modification. Obtain the modified system time, and calculate the time offset according to the modified system time and the current system time predicted by the second timer; Accumulate the calculated time offset and the system time offset recorded in the system time offset configuration file, and write the calculation result back to the system time offset configuration file as a new system time offset; Update the timer to regularly update the system duration value; The first thread is called to adjust the system time offset or the network time protocol time offset.

7. The method according to claim 6, characterized in that The receiving system usage duration query request includes: Each time the system is started, a third thread is generated using the system time offset configuration file, and the third thread is used to receive a system usage time query request in real time; The third thread is used to perform the following operations: Connect and set the callback function of dbus interface get-usedtime; Call the get-usedtime callback function to calculate the current usage time of the operating system and the time difference between the current time and the system's full-day usage time. After using the time difference for a whole day, a message is sent to the dbus client, the message carries the variable system usage time for a whole day, and a timer is set to cyclically send messages to the dbus client with a third preset time as a period.

8. The method according to claim 1, characterized in that The method of using the process communication mechanism to read the system time offset configuration file includes: Determine the system time offset configuration file according to the set storage path and file name, and read the string content in the configuration file; Create at least two variables of type GKeyFile; Decode the string using Base64 encoding; The decoding result is loaded into the GKeyFile variable as data, and the group name and key name are specified, and the corresponding variable value is obtained through the GKeyFile data reading interface.

9. A system duration acquisition device, characterized in that: include: A receiving module, used to receive a system usage time query request by using a process communication mechanism, read a system time offset configuration file, the system time offset configuration file is generated when the system is installed, and records the system time offset and the network time protocol time offset, the system time offset is updated with the system time modification event; Reading module, used to read the current system time; The determination module is used to read the system time offset and the network time protocol time offset from the system time offset configuration file, and determine the system duration according to the network time protocol time offset and the system time offset and the current system time.

10. A storage medium containing computer executable instructions, characterized in that: When the computer executable instructions are executed by a computer processor, they are used to execute the system duration acquisition method as described in any one of claims 1-8.