当前位置:网站首页>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 .
边栏推荐
- Three layer switching ①
- A. Min Max Swap
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- I don't know why it can't run in the project and how to change it
- Jerry's watch information type table [chapter]
- Basic editing specifications and variables of shell script
- Jerry's update contact [article]
- MySQL statement learning record
- Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
- Méthode de calcul de la connexion MSSQL de la carte esp32c3
猜你喜欢
Small program graduation project based on wechat reservation small program graduation project opening report reference
Audio resource settings for U3D resource management
Pytoch residual network RESNET
Conditional statements of shell programming
Feign implements dynamic URL
Magical usage of edge browser (highly recommended by program ape and student party)
JVM performance tuning and practical basic theory - medium
Setting function of Jerry's watch management device [chapter]
Yyds dry goods inventory hand-in-hand teach you the development of Tiktok series video batch Downloader
Final consistency of MESI cache in CPU -- why does CPU need cache
随机推荐
Gee: create a new feature and set corresponding attributes
Solution to the problem that jsp language cannot be recognized in idea
LeetCode226. Flip binary tree
The automatic control system of pump station has powerful functions and diverse application scenarios
Neo4j learning notes
Huawei cloud micro certification Huawei cloud computing service practice has been stable
SRCNN:Learning a Deep Convolutional Network for Image Super-Resolution
Prose article appreciation - the rain in the warm country has never changed into cold, hard and brilliant flowers. Knowledgeable people think he is monotonous, and he thinks he is unlucky, doesn't he?
Cancer biopsy instruments and kits - market status and future development trends
51 MCU external interrupt
ThinkPHP uses redis to update database tables
How can enterprises optimize the best cost of cloud computing?
Basic editing specifications and variables of shell script
Customize redistemplate tool class
Why can't it run (unresolved)
All ceramic crowns - current market situation and future development trend
Infiltration learning diary day19
MySQL advanced SQL statement (1)
Pesticide synergist - current market situation and future development trend
LV1 previous life archives