How is the time utility affected by multithreading?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How is the time utility affected by multithreading?
If I run the time command around a multi-threaded application, how is it affected? In this case, what do the user and sys times represent? Is it the sum of all times used by the various threads, or...?
The times reported for a process will be the time consumed by that process alone ... but this will be somewhat-less than elapsed time, and this is where/how the effect of multitasking can be seen.
When the dispatcher hands control to a process/thread, and then takes it away again a few microseconds later, it keeps an accounting of how much time the process consumed. When the process makes system-calls and subsequently returns from those calls, the elapsed-time spent servicing a system-call is also accounted for.
All of these times are intended to be used only for comparative purposes. They are not exact, and they can vary due to a myriad of possible factors.
"This is why I am wondering if "user" is the sum of the times, since presumably otherwise user cannot be greater than actual elapsed time, right?"
An application's time can be greater than real time if the application is multi-threaded and you time the application on a multi-CPU machine. However an application's time cannot be greater than real time multiplied by the number of CPUs.
I have done such multi-CPU timings on IBM mainframes where the application time exceeded real time but I have never tried to do it on an x86.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.