我是靠谱客的博主 优秀百褶裙,这篇文章主要介绍在内核获取时间 精度纳秒级,现在分享给大家,希望可以做个参考。

原文地址:http://blog.chinaunix.net/uid-20583479-id-1920140.html


程序代码:
    struct timespec ts;
    ts = current_kernel_time();
    printk(KERN_ALERT "%ld %ldn", ts.tv_sec, ts.tv_nsec);
   
    struct timeval tv;
    /*获取时间*/
    do_gettimeofday(&tv);
    printk(KERN_ALERT "now: %ld %ldn", tv.tv_sec, tv.tv_usec);
    /*设置时间, 时钟调后5小时*/
    ts.tv_sec = tv.tv_sec + 3600*5;
    do_settimeofday(&ts);
    printk(KERN_ALERT "after 5 hours: %ld %ldn", tv.tv_sec, tv.tv_usec);

输出日志:

Jun 30 23:17:29 localhost kernel: now: 1309447049 608761
Jun 30 23:17:29 localhost kernel: after 5 hours: 1309447049 608761
Jun 30 23:18:13 localhost kernel: Goodbye, cruel world
Jul  1 04:18:22 localhost kernel: Hello, world
Jul  1 04:18:22 localhost kernel: 1309447102 738475231
Jul  1 04:18:22 localhost kernel: now: 1309447102 739073
Jul  1 04:18:22 localhost kernel: after 5 hours: 1309447102 739073

最后

以上就是优秀百褶裙最近收集整理的关于在内核获取时间 精度纳秒级的全部内容,更多相关在内核获取时间内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(116)

评论列表共有 0 条评论

立即
投稿
返回
顶部