关于linux下时间函数的问题

fanchuan 2007-06-06 01:15:41
我用了getrusage()函数来得到这个program的使用时间,和它的系统时间。

int getrusage(int who,struct rusage * usage);

struct rusage {
struct timeval ru_utime; //user time used
struct timeval ru_stime; //system time used
.....

}

就是说,我用的是utime and stime。现在的问题是,什么时间包含在用户时间?什么时间包含在系统时间? 我的理解是如果是在程序里有系统调用,那么这些系统调用的时间就是此程序的系统时间,比如,Openfile()close()等等。其余的程序时间就是程序的用户时间。

我发现有些帖子说道别的函数,time()--秒级别,clock()-毫秒级别。我的问题是,为什么这个函数的精度不够?是因为记录时间的字段比较短?


多谢多谢



...全文
626 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanchuan 2007-06-06
  • 打赏
  • 举报
回复
能不能具体一些啊?
hailongchang 2007-06-06
  • 打赏
  • 举报
回复

http://blog.csdn.net/hailongchang/archive/2006/12/13/1441079.aspx


http://blog.csdn.net/hailongchang/archive/2006/12/15/1444365.aspx
kf701 2007-06-06
  • 打赏
  • 举报
回复
User Time
This is the amount of time the command spends in "User Mode." User Mode is a "safety" feature because when a program is in User Mode it cannot cause other programs to crash, or behave unexpectedly.

System Time
System Time is the amount of time the command spends in "Kernel Mode." There are certain tasks a command must run in Kernel Mode to accomplish, however since a command can misbehave while in Kernel Mode, they only go into Kernel Mode when they have to do so.

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧