当前位置:网站首页>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 .
边栏推荐
- Feign implements dynamic URL
- High level application of SQL statements in MySQL database (I)
- How programmers find girlfriends through blind dates
- Some other configurations on Huawei's spanning tree
- From the 18th line to the first line, the new story of the network security industry
- The contact data on Jerry's management device supports reading and updating operations [articles]
- Description of setting items of Jerry [chapter]
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- Intel's new GPU patent shows that its graphics card products will use MCM Packaging Technology
- Portable two-way radio equipment - current market situation and future development trend
猜你喜欢
![When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]](/img/fb/7d4a026260f8817460cc67f06e49ae.jpg)
When the watch system of Jerry's is abnormal, it is used to restore the system [chapter]

High level application of SQL statements in MySQL database (I)

Yyds dry goods inventory hand-in-hand teach you the development of Tiktok series video batch Downloader

Do you know the eight signs of a team becoming agile?

Force buckle day32

How can enterprises optimize the best cost of cloud computing?

Use classname to modify style properties

Chain ide -- the infrastructure of the metauniverse

Infiltration learning diary day19
![[turn] solve the problem of](/img/c2/368582a8ed26254409fe391899ba41.jpg)
[turn] solve the problem of "RSA public key not find" appearing in Navicat premium 15 registration
随机推荐
Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
The reasons why QT fails to connect to the database and common solutions
C import Xls data method summary III (processing data in datatable)
I don't know why it can't run in the project and how to change it
The difference between lambda expressions and anonymous inner classes
Some other configurations on Huawei's spanning tree
Huawei cloud micro certification Huawei cloud computing service practice has been stable
Day05 branch and loop (II)
Small program graduation project based on wechat examination small program graduation project opening report function reference
Maximum entropy model
Cancer biopsy instruments and kits - market status and future development trends
C import Xls data method summary V (complete code)
Why can't it run (unresolved)
Openbionics robot project introduction | bciduino community finishing
The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
1189. Maximum number of "balloons"
Summary of JWT related knowledge
Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
Do you know the eight signs of a team becoming agile?
Skku| autonomous handover decision of UAV Based on deep reinforcement learning