Age of a process in the Linux kernel

强颜欢笑 提交于 2020-01-14 05:42:29

问题


Given the struct task_struct to work with. What's the best way to determine how old a process is?

The task_struct is used to hold specific pointers to it's next youngest sibling, and oldest child. That no longer seems to be available in some kernel versions.

I'm specifically using the Android goldfish kernel. I've been trying to learn how to use the list_head structure to iterate over processes, but I can't seem to figure out how to determine the age of each child or sibling process.

So, what member or usage of task_struct would do this?


回答1:


I think you can use real_start_time or start_time in task_struct. It is updated at the time of process creation

    struct timespec start_time;             /* monotonic time */
    struct timespec real_start_time;        /* boot based time */

Note: this is vanilla kernel no idea about android kernel




回答2:


How about keeping things simple and looking ctime of /proc/PID/ for each process you are interested. Please notice that possible clock adjustments may make the ctime to look strange, and good program should not fail if elapsed time is negative due to such event.



来源:https://stackoverflow.com/questions/23178888/age-of-a-process-in-the-linux-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!