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-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article will explain in detail how to use the time command in Linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The Linux common command time command is used to count the total time spent on a given command.

Time counts the total time spent on a given command

Syntax time (parameter) parameter instruction: specifies the amount of instruction to be run and its parameters.

When testing a program or comparing different algorithms, the execution time is very important, and a good algorithm should take the shortest time. All UNIX-like systems include the time command, which allows you to count the time spent. For example:

The information output from [root@localhost ~] # time ls anaconda-ks.cfg install.log install.log.syslog satools text real 0m0.009s user 0m0.002s sys 0m0.007s shows the real time, user time, and sys time spent by the command, respectively.

Real time refers to the wall clock time, that is, the time from the beginning of the command to the end of the command. This short time includes the time slice taken by other processes and the time spent when the process is blocked.

User time is the CPU time that the process spends in user mode, which is the only time spent actually executing the process, not counting the other processes and the time spent in the blocking state.

Sys time refers to the CPU time spent in kernel mode, which represents the time spent executing system calls in the kernel, which is also the CPU time actually used by the process.

Shell built-in also has a time command, which is called when running time. The built-in function of the system should be limited, so it takes time for other functions to use time commands to execute binaries / usr/bin/time.

Use the-o option to write the execution time to the file:

/ usr/bin/time-o outfile.txt ls uses the-an option to append information:

/ usr/bin/time-a-o outfile.txt ls uses the-f option to format the time output:

Parameters after / usr/bin/time-f "time:% U" ls-f option:

Parameter describes% Ereal time, displayed in [hours:] minutes: seconds% Uuser time. % Ssys time. % C command name and command line arguments for timing. % D process is not a shared data area, in KB. % x command exit status. The number of signals received by the k process. % w the number of times the process was swapped out of main memory. The page size of the% Z system, which is a system constant and varies without the constant value in the system. The% P process gets 100 percent of the CPU time, which is equal to the user+system time divided by the total elapsed time. Average total memory usage (data+stack+text) for K processes, in KB. The number of times the w process actively switched contexts, such as waiting for the Imax O operation to complete. The number of times the c process was forced to make a context switch (due to the expiration of the time slice). This is the end of the article on "how to use time commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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