The BSD sysctl() syscall has a top-level "directory" called "kern", and one of the second-level directories under that is "proc". This is used for getting process information and has several third-level directories for filtering which processes are included. In my version of top I use the "all" value for retrieving information for all processes.
Here is what "top" currently looks like (r377 in the trunk):
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFef_9ZnwX0iTao3AQkkAU4VIiG7YVjTx4DQpnizjbobdrzXK-ej-gUlaAXvX5VfZkQu9XX4Ter4_Ql7Jprpl0ZYQzEbi_D_X_vtlOY-QKHGQKE4RrdefCu3kf0wJFoLoaSPlxaYCKas4h/s1600/top-2011-03-17.png)
As you can see, some values are -1. These are statistics that I have not gathered yet, either in the kernel or in top. I still have to add memory statistics in the kernel, for example.
Also, the CPU usage reported for top itself is much lower than before (0.5 vs 2.5). This is because the older top code used getrusage() to calculate CPU usage (as change in CPU time divided by change in real time), while this latest version uses the kp_pcpu field in struct kinfo_proc from sysctl(). This field is maintained in the kernel as an exponential moving average of CPU usage rather than a linear moving average, so it will naturally be different from the old method.
3 comments:
For reference, FreeBSD also uses sysctl, not /proc. In fact /proc is completely optional on FreeBSD.
Thanks for the information, dTal. I didn't look into how modern BSD systems supported process statistics. I just assumed they might also use the /proc filesystem.
Post a Comment