免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2354 | 回复: 1
打印 上一主题 下一主题

[Linux] times函数的问题哦 [复制链接]

论坛徽章:
2
IT运维版块每日发帖之星
日期:2016-01-16 06:20:00数据库技术版块每日发帖之星
日期:2016-03-10 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-24 15:23 |只看该作者 |倒序浏览
int main(int argc, char **argv)
{
        clock_t stime, etime;
        struct tms sbuf, ebuf;
        int status;
        static long clktck = 0;

        if ((stime = times(&sbuf)) == -1)
                err_sys("times error");
        if ((status = system("sleep 1; pwd")) < 0)
                err_sys("system error");
        if ((etime = times(&ebuf)) == -1)
                err_sys("times error");
       
        clktck = sysconf(_SC_CLK_TCK);
        printf("rtime: %7.2f\n", (etime-stime)/(double)clktck);
        printf("utime: %7.2f\n", (ebuf.tms_utime - sbuf.tms_utime)/(double)clktck);
        printf("stime: %7.2f\n", (ebuf.tms_stime - sbuf.tms_stime)/(double)clktck);
        printf("cutime: %7.2f\n", (ebuf.tms_cutime - sbuf.tms_cutime)/(double)clktck);
        printf("cstime: %7.2f\n", (ebuf.tms_cstime - sbuf.tms_cstime)/(double)clktck);

        exit(0);
}



平安夜一点不平安,呵呵,为啥只有rtime是对的,stime和utime都是0呢???

论坛徽章:
0
2 [报告]
发表于 2015-01-05 22:09 |只看该作者
utime的意思是进程消耗cpu的时间;stime是消耗系统的时间。详细例子见:
blog.sina.com.cn/s/blog_590be5290100nctf.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP