6 ms·
Traditional Unix implementation of ps and similar tools work by directly reading the appropriate data structures from kernel (through /dev/kmem or something to
by dfox 7y ago
Traditional Unix implementation of ps and similar tools work by directly reading the appropriate data structures from kernel (through /dev/kmem or something to that effect). Modern BSD implementations have libkvm.a, that abstracts that somehow, but still directly reads stuff from kernel space.
I don't know, but I don't see doing random reads from kernel memory as particularly sane API to get list of processes and procfs is several orders of magnitude cleaner solution.
- twic 7y agoGetting a list of numbers from the kernel by serialising them as text in a pretend filesystem is a several orders of magnitude cleaner solution?
- luke0016 7y ago> Traditional Unix implementation of ps and similar tools work by directly reading the appropriate data structures from kernel (through /dev/kmem or something to that effect). This is not correct - /dev/kmem and similar are typically only readable by root. If what you say were correct, ps and friends wouldn't work for unprivileged users (unless they were setuid root, which they're not).
- Erwin 7y agoSome version of *BSDs probably fixed that with some sysctl interface, but on older Unixes you would read the kernel memory to get that system information. You can see a ps.c implementation here: https://searchcode.com/codesearch/view/29853364/ https://searchcode.com/codesearch/view/29853364/ which uses kvm library: https://www.freebsd.org/cgi/man.cgi?query=kvm&sektion=3&apropos=0&manpath=FreeBSD+12.0-RELEASE+and+Ports https://www.freebsd.org/cgi/man.cgi?query=kvm&sektion=3&apro...
- trasz 7y agoFWIW, in FreeBSD libkvm also uses the sysctl interface, it doesn’t read kernel memory directly.