当前位置:网站首页>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 .
边栏推荐
- Some other configurations on Huawei's spanning tree
- Small program graduation project based on wechat reservation small program graduation project opening report reference
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- Jerry's modification setting status [chapter]
- LV1 previous life archives
- Pyrethroid pesticide intermediates - market status and future development trend
- A. Min Max Swap
- C import Xls data method summary I (upload files and create Workbooks)
- Chinese Mitten Crab - current market situation and future development trend
- ThinkPHP uses redis to update database tables
猜你喜欢

Maximum entropy model

Small program graduation project based on wechat reservation small program graduation project opening report reference

TP5 automatic registration hook mechanism hook extension, with a complete case

Small program graduation project based on wechat examination small program graduation project opening report function reference

Chapter 3.4: starrocks data import - Flink connector and CDC second level data synchronization

SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution

Introduction to graphics: graphic painting (I)

Feign implements dynamic URL

Use classname to modify style properties

Remember another interview trip to Ali, which ends on three sides
随机推荐
Solution to the problem that jsp language cannot be recognized in idea
All metal crowns - current market situation and future development trend
A. Min Max Swap
Introduction to graphics: graphic painting (I)
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
Neo4j learning notes
The difference between lambda expressions and anonymous inner classes
How programmers find girlfriends through blind dates
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
What are the main investment products of bond funds and what are they
Will the memory of ParticleSystem be affected by maxparticles
How can enterprises optimize the best cost of cloud computing?
Huawei BFD and NQA
Pesticide synergist - current market situation and future development trend
Feign implements dynamic URL
Why can't it run (unresolved)
Applet graduation project based on wechat selection voting applet graduation project opening report function reference
1189. Maximum number of "balloons"
MySQL deadly serial question 2 -- are you familiar with MySQL index?
Make drop-down menu