Kernel Monitor?

Andrey Simonenko simon at comsys.ntu-kpi.kiev.ua
Mon Feb 14 05:57:40 PST 2005


>   FOREACH_PROC_IN_SYSTEM(p) {
>     mtx_lock(&Giant);
>     PROC_LOCK(p);
>     printf("%d %d\n", (int)p->p_stats->p_ru.ru_isrss, (int)p->p_stats->p_ru.ru_idrss);
>     PROC_UNLOCK(p);
>     mtx_unlock(&Giant);
>   }

This code is incorrect, because you should get sx_slock(&allproc_lock)
before FOREACH_PROC_IN_SYSTEM and release sx_sunlock(&allproc_lock)
after this loop.  If you don't do this, then p in some iteration
will point to nothing.  Locking Giant, as I understand, here is not
required (even vefore FOREACH_...).


More information about the freebsd-hackers mailing list