Converting jiffies to milli seconds

前端 未结 4 1814
生来不讨喜
生来不讨喜 2020-12-04 11:42

How do I manually convert jiffies to milliseconds and vice versa in Linux? I know kernel 2.6 has a function for this, but I\'m working on 2.4 (homework) and though I looked

4条回答
  •  情歌与酒
    2020-12-04 12:03

    I found this sample code on kernelnewbies. Make sure you link with -lrt

    #include 
    #include 
    #include 
    
    int main()
    {
        struct timespec res;
        double resolution;
    
        printf("UserHZ   %ld\n", sysconf(_SC_CLK_TCK));
    
        clock_getres(CLOCK_REALTIME, &res);
        resolution = res.tv_sec + (((double)res.tv_nsec)/1.0e9);
    
        printf("SystemHZ %ld\n", (unsigned long)(1/resolution + 0.5));
        return 0;
     }
    

提交回复
热议问题