Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the time command in Linux

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use the time command in Linux. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Linux commonly used commands time commands are used to measure information such as time and system resources required for the execution of specific instructions.

Syntax time [options] COMMAND [arguments] parameters:

-o or-output=FILE: set the result output file. This option writes the output of time to the specified file. If the file already exists, the system will overwrite its contents.

-an or-append: when used with-o, the result is written to the end of the file without overwriting the original content.

-f FORMAT or-format=FORMAT: sets the display mode as the FORMAT string. When this option is not set, the default format is used. However, you can use the environment variable time to set this format, so you don't have to set it every time you log in to the system.

There are four major resources that can be displayed by the time directive, which are:

Time resources

Memory resources

IO resources

Command info

The details are as follows:

1 、 Time Resources

E the time it takes to execute an instruction in the format: [hour]: minute:second. Please note that this number does not represent the actual CPU time.

E the time in seconds it takes to execute an instruction. Please note that this number does not represent the actual CPU time.

The time, in seconds, spent in core mode (kernel mode) when the S instruction is executed.

The time, in seconds, spent in user mode (user mode) when the U instruction is executed.

P the proportion of CPU when the instruction is executed. In fact, this number is the core mode plus the user mode CPU time divided by the total time.

2 、 Memory Resources

The maximum amount of physical memory occupied by M during execution. The unit is KB

The average amount of physical memory occupied by t execution, in KB

K the average size of the total memory occupied by the executing program (stack+data+text), in KB

The average size of the own data area (unshared data area) of the executor, in KB

P the average size of the own stack (unshared stack) of the executor, in KB

X average of content shared between programs (shared text) in KB

The size of the memory page of the Z system, in byte. It's a constant for the same system.

3 、 IO Resources

F the number of main memory page errors in this program. The so-called main memory page error means that a memory page has been replaced in the replacement file (swap file) and has been assigned to other programs. At this point, the contents of the page must be read again from the replacement file.

R the number of secondary memory page errors in this program. The so-called secondary memory page error means that although a memory page has been replaced in the replacement file, it has not been assigned to other programs. At this time, the content of the page has not been destroyed and does not have to be read from the replacement file.

W the number of times this program has been swapped to the replacement file

C the number of times this program has been forced to interrupt (such as running out of allocated CPU time)

W the number of times this program has been interrupted voluntarily (such as waiting for a certain Imax O to finish execution, such as disk reading, etc.)

I the number of files entered by this program

O the number of files output by this program

R Socket Message received by this program

S the Socket Message sent by this program

K the number of signals (Signal) received by this program

4 、 Command Info

Parameters and instruction names when C executes

The end code of the x instruction (Exit Status)

-por-portability: this option automatically sets the display format to:

Real% e user% Usys% S: the purpose of this is to be compatible with the POSIX specification.

-v or-verbose: this option lists all the resources used in the program, not only in general English sentences, but also in instructions. It's useful for people who don't want to take the time to familiarize themselves with formatting or are just beginning to get started with this instruction.

Example 1. # time date2. Sun Mar 26 22:45:34 GMT-8 20063.4. Real 0m0.136s5. User 0m0.010s6. Sys 0m0.070s7. # in the above example, execute the command "time date" (see line 1).

The system first executes the command "date", and the second behavior command "date" is executed.

The third-sixth behavior executes the time statistics of the command "date", in which line 4 "real" is the actual time, line 5 "user" is the user CPU time, and line 6 "sys" is the system CPU time.

The display format of the above three times is MMmNN [.FFF] s.

Use the following instructions

Time-v ps-aux We can get the results of executing ps-aux and the system resources spent. As listed below:

USER PID% CPU% MEM VSZ RSS TTY STAT START TIME COMMANDroot 1 0.00.4 1096 472? S Apr19 0:04 initroot 2 0.0 0.0 0 0? SW Apr19 0:00 [kflushd] root 3 0.0 0.0 00? SW Apr19 0:00 [kpiod]. Root 24269 0.0 2692 996 pts/3 R 12:16 0:00 ps-auxCommand being timed: "ps-aux" User time (seconds): 0.05System time (seconds): 0.06Percent of CPU this job got: 68%Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.16Average shared text size (kbytes): 0Average unshared data size (kbytes): 0Average stack size (kbytes): 0Average total size ( Kbytes): 0Maximum resident set size (kbytes): 0Average resident set size (kbytes): 0Major (requiring I kbytes) page faults: 238Minor (reclaiming a frame) page faults: 46Voluntary context switches: 0Involuntary context switches: 0Swaps: 0File system inputs: 0File system outputs: 0Socket messages sent: 0Socket messages received: 0Signals delivered: 0Page size (bytes): 4096Exit status: 0 is all the content of the article "how to use time commands in Linux" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report