当前位置:网站首页>14. Process time
14. Process time
2022-07-04 01:58:00 【666QAQ】
Concept
Process time is process After creation The use of CPU The amount of time . For the purpose of recording , The kernel puts CPU Time is divided into the following two parts .
- user CPU Time is the amount of time spent executing in user mode , Also known as virtual time (virtual time), This is for programs , Yes, it has been CPU Time for .
- System CPU Time is the amount of time spent executing in kernel mode . This is the time that the kernel uses to perform system calls or other tasks on behalf of programs .
When we run a shell Program , have access totime(1)command , To get the time of these two parts and the actual time required to run the program at the same time .
Such as :
time ./a.out
times() call
system call times() Retrieve process time information , And pass the result through buf The structure pointed to returns i.
#include <sys/time.h>
clock_t times(struct tms *buf);
Returns number of clock ticks(sysconf(_SC_CLK_TCK)) since "arbitrary"
time in past pn success, or (clock_t)-1 on error.
buf Point to the TMS The structure has the following format :
struct tms{
clock_t tms_utime; /*User CPU used by caller*/
clock_t tms_stime; /*System CPU time used by caller*/
clock_t tms_cutime; /*User CPU time of all (waited for) children*/
clock_t tms_cstime; /*System CPU time of all (waited for) children*/
};
Parameter description
tms The first two fields of the structure return the user and system components used by the calling process so far CPU Time . The last two fields are : The parent process ( such as ,times() The caller ) A system call was executed wait() Used by all terminated subprocesses of CPU Time .
data type clock_t It is a clock timing unit (closk tick) The unit measurement is the integer value of time , Used for calculation tms Structure of the 4 A field . You can call sysconf(_SC_CLK_TCK) To get the number of clock timing units per second , Then divide this number by clock_t Convert to seconds .
Return value
If it works ,times() Returns the time elapsed at any point in the past, in units of clock timing units ( Actual ) Time .SUSv3 There is no definition of what this is , Just say , Zhejiang is a fixed point in the life cycle of the calling process .
therefore , The only use of this return value is by calculating a pair times() The difference between the values returned by the call , To calculate the time consumed by the process execution .( However , Even this is not reliable , Because it may overflow clock_t The effective range of , At this time times() The return value of will again be from 0 Start calculating ). The reliable way is to use functions gettimeofday()
clock()
function clock() It provides a simple interface for obtaining process time , It returns a value that describes the total... Used by the call CPU Time ( Including users and systems ).
#include <time.h>
clock_t clock(void);
Returns total CPU time used by calling process measured in
CLOCKS_PER_SEC, or (clock_t)-1 on error.
The unit of measurement is CLOCK_PER_SEC, Divide by this value to get the number of seconds .
In some UNIX On the system clock() The returned time includes all the time waiting for the child process , But in Linux On , barring .
边栏推荐
- Lightweight Pyramid Networks for Image Deraining
- Use classname to modify style properties
- A. Min Max Swap
- [turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration
- Gee: create a new feature and set corresponding attributes
- Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
- Openbionics exoskeleton project introduction | bciduino community finishing
- How can enterprises optimize the best cost of cloud computing?
- Méthode de calcul de la connexion MSSQL de la carte esp32c3
- Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales
猜你喜欢

2020-12-02 SSM advanced integration Shang Silicon Valley

What is the intelligent monitoring system of sewage lifting pump station and does it play a big role

MySQL advanced SQL statement (1)

LV1 previous life archives

LeetCode226. Flip binary tree

Override and virtual of classes in C #

Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.

Bacteriostatic circle scanning correction template

Applet graduation design is based on wechat course appointment registration. Applet graduation design opening report function reference

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
随机推荐
Introduction to Tianchi news recommendation: 4 Characteristic Engineering
Jerry's watch information type table [chapter]
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
Magical usage of edge browser (highly recommended by program ape and student party)
1189. Maximum number of "balloons"
Notice on Soliciting Opinions on the draft of information security technology mobile Internet application (APP) life cycle security management guide
Servlet simple verification code generation
Day05 branch and loop (II)
C import Xls data method summary I (upload files and create Workbooks)
Ceramic metal crowns - current market situation and future development trend
51 MCU external interrupt
Learn these super practical Google browser skills, girls casually flirt
Solution to the problem that jsp language cannot be recognized in idea
What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
Audio resource settings for U3D resource management
Pytoch residual network RESNET
Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
The difference between lambda expressions and anonymous inner classes
Flex flexible layout, box in the middle of the page
TP5 automatic registration hook mechanism hook extension, with a complete case