Search code examples
clinuxlinux-kerneltaskandroid-kernel

Age of a process in the Linux kernel


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?


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