convert jiffies to seconds

后端 未结 4 577
悲&欢浪女
悲&欢浪女 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:14

    Source of "ps" command include file to get value of HZ.

    They also look for an "ELF note" with number 17 to find value of HZ (sysinfo.c):

     //extern char** environ;
    
     /* for ELF executables, notes are pushed before environment and args */
     static unsigned long find_elf_note(unsigned long findme){
       unsigned long *ep = (unsigned long *)environ;
       while(*ep++);
       while(*ep){
         if(ep[0]==findme) return ep[1];
         ep+=2;
       }
       return NOTE_NOT_FOUND;
     }
     [...]
     hz = find_elf_note(17);
    

    I have to admit it look weird for me since ELF notes is a section defined during compilation.

提交回复
热议问题