Go run strace on ps or top and see what they call.
I'll save you some time: it turns out to be stat() and open() on things in /proc.