Re:Sloth – Mac app that shows all open files and sockets in use
by rabidcondor on Thursday February 14, 2019 @11:02AM
(#19162881)
macOS, with its BSD roots, doesn't have a proc filesystem.
Re:Sloth – Mac app that shows all open files and sockets in use
by comex on Thursday February 14, 2019 @05:04PM
(#19166515)
If anyone's curious: Traditionally, lsof on BSD would just open /dev/kmem and read the info directly out of the kernel's data structures! It still does that on FreeBSD, and used to do it on macOS prior to 2006, when Apple added the more sensible (and stable) libproc.h API in one of the Tiger software updates.
Sloth dates back to 2004, at which point parsing lsof's output would definitely have been a more sensible choice than replicating the kmem parsing code. On the other hand, if I were writing something like Sloth today, though, I'd use libproc, because I think it'd be easier overall, and it would also make it more feasible to improve the core functionality (like adding a progress bar or lazy querying).
However, lsof does have a flag (-F) to specify how to format its output, explicitly documented in the man page as being intended for other programs that want to parse its output, implying that it will remain stable. And Sloth uses this flag. Thus, even from a modern perspective, its approach is perfectly reasonable.
Re:Sloth – Mac app that shows all open files and sockets in use
by lawnchair_larry on Friday February 15, 2019 @01:46AM
(#19168966)
Huh, so that means you need root to run lsof on freebsd?
By contrast, lsof can change output at any time. I've not done enough parsing of lsof to be familar with past changes, but have seen meaningful changes in the default output of lsblk, df, and other core CLI tools that wrap system information.