convert jiffies to seconds

后端 未结 4 547
悲&欢浪女
悲&欢浪女 2021-01-04 18:28

I\'ve got a piece of userspace code which is parsing /proc/PID/task/TID/stat to get the cpu usage. I can use HZ to get the jiffies per second but this code could move to an

4条回答
  •  悲&欢浪女
    2021-01-04 19:16

    For shell-scripting, etc, use getconf CLK_TCK from the command-line. Use can use this to pass that parameter in as an environment variable or on the command-line.

    main(int argc, char **argv) { 
        unsigned long clk_tck = atol(
            getenv("CLK_TCK") || "0"
        ) || sysconf(_SC_CLK_TCK) ;
        ... /* your code */
    

    This uses the sysconf as above, but allows you to override it with an environment variable, which can be set with the above command.

提交回复
热议问题