0

I would like to get the task_struct of a process by his PID because I need the timing fields for a monitoring application. Is that possible without creating a module ? If not, is there a way to get the start time of the process, his execution time in user and kernel modes, his last execution ... etc

0

The task_struct is not directly exposed, but a lot is available in /proc/PID, which is documented in proc(5). In particular /proc/PID/stat has a number of fields which looks like this.

663969 (bash) S 255279 663969 663969 34836 721047 4194304 1103 125311 1 2396 1 2 2385 4333 20 0 1 0 152947991 9584640 1123 18446744073709551615 94761163685888 94761164450717 140730124580704 0 0 0 65536 3686404 1266761467 0 0 0 17 0 0 0 5 0 0 94761164686000 94761164733764 94761175252992 140730124584237 140730124584243 140730124584243 140730124586990 0

The 1-based fields include the PID 663969 (field 1), the PPID 255279 (field 4), the execution time in user space 1 (field 14) and system space 2 (field 15), and the start time 152947991 (field 22 in clock ticks). Not clear what last execution means.

1
  • Thanks for the answer. The problem is that I need a higher resolution of the execution time and the field in /proc/PID/stat is not enough. By last execution l meant the time when the process left the cpu. Dec 27 '20 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.