Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top