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 time command in Linux system

2025-01-18 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 the Linux system, the article is very detailed, has a certain reference value, interested friends must read it!

On Linux systems, the time command is used to determine how long it takes for a specified command to run. It is useful for testing the performance of scripts and commands.

Command format time`` [options] ``command`` [arguments...] * * option description * *-f FORMAT,-- format=FORMAT: output using the specified format. If no output format is specified, use the format-p,-- portability specified by the environment variable TIME: use the compatible output format, real% e user% U sys% S, in order to be compatible with the POSIX specification-o FILE,-- output=FILE: set the result output file. This option writes the output of time to the specified file. If the file already exists, override its contents-a,-append: used with the-o option, use the append mode to write the output to the specified file-v,-- verbose: use redundant mode to output statistics as much as possible-- help: display help-V,-- version: display version information--: terminate the list of options where the output format is interpreted in a printf-like manner Ordinary characters will be output directly, with tabs, line feeds, and backslash percent signs, represented by\ t,\ n,\ and%, respectively. % is followed by other letters to indicate a special format, and the available formats are as follows:

Time% E: time spent executing instructions, format [hours:] minutes:seconds% e: time spent executing instructions, in seconds% S: time spent in kernel mode (kernel mode) during instruction execution, in seconds% U: time spent in user mode (user mode) during instruction execution, in seconds% P: percentage of CPU during instruction execution. In fact, this number is the maximum amount of memory used in kernel mode plus user mode CPU time divided by total time (% slots% U) /% E) Memory% M: execution. Unit KB% t: average amount of memory occupied during execution, in KB% K: average size of total memory occupied by executing program (stack+data+text) in KB% D: average size of own data area (unshared data area) of executing program in KB% p: average size of own stack (unshared stack) of executing program in KB% X: average size of shared code segment (shared text) of executing program The unit is KB% Z: the size of the system memory page, in byte. For the same system, this is a constant% F: the number of memory page errors. Memory page error refers to the number of page errors that need to be read from disk to memory% R: secondary or recoverable. These are errors for invalid pages, but the memory page has not been used by other virtual pages. Therefore, the data in the page is still valid, but the system table% W: the number of times the process swapped from memory% c: the number of times the process context was switched (because the time slice has expired)% w: the number of times the process waited, which refers to the number of times the program actively switched the context. For example, wait for Socket Message O% I: number of files entered by this program% O: number of files output by this program% r: number of Socket Message% s received by this program: number of signals (Signal) received by this program Command Info% C: parameters at execution and instruction name% x: end code of instruction (Exit Status) case Example demonstration 1. # time date 2. Sun Mar 26 22:45:34 GMT-8 2006 3. 4. Real 0m0.136s 5. User 0m0.010s 6. Sys 0m0.070s 7. # 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 COMMAND root 1 0.00.4 1096 472? S Apr19 0:04 init root 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.01.0 2692 996 pts/3 R 12:16 0:00 ps-aux Command being timed: "ps-aux" User time (seconds): .05 System time (seconds): 0.06 Percent of CPU this job got: 68% Elapsed (wall clock) time (h:mm:ss or m:ss): 00.16 Average shared text size (kbytes): 0 Average unshared data size (kbytes): 0 Average stack size (kbytes): 0 Average total size (kbytes): 0 Maximum resident set Size (kbytes): 0 Average resident set size (kbytes): 0 Major (requiring I page faults O) page faults: 238 Minor (reclaiming a frame) page faults: 46 Voluntary context switches: 0 Involuntary context switches: 0 Swaps: 0 File system inputs: 0 File system outputs: 0 Socket messages sent: 0 Socket messages received: 0 Signals delivered: 0 Page size (bytes): 4096 Exit status: 0 above is all the content of the article "how to use the time Command in Linux system" 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