-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE] Expose functionality as a re-usable library #268
Comments
Reading the code, the dialect-specific code and user-interfacing code is tightly coupled via global variables, and there is extensive usage of static variables. It will be a very big project ;) Maybe suitable for a GSoC? |
I made some progress at https://github.com/jiegec/lsof/blob/library/include/lsof.h, you can see API definitions there, and here is a list of DONEs and TODOs:
|
Had a quick look at the API: Looks good so far. Probably some suggestions:
From the PoV of an implementer of a system monitoring tool that tracks process information itself: How would I go about receiving updated information about open files for one process in a regular interval (polling is totally fine and expected, the updating part is the focus here)? As I read the API now I'd have to create a completely new context each time causing quite some information to be collected each time (in particular process information) that are thrown away again; or am I missing sth here? Regarding platform support: How about extending support to FreeBSD and Darwin next? |
DONE
Actually,
Which is a big mess, and even the regular file is represented as
Yes, working on it. But unix domain socket is special, it is currently reported in
Yes, WIP.
Good idea, I can also use this way to report selection results. lsof cli requires this information to report and set exit code.
Thanks for the suggestions, I will work on it after finishing FreeBSD support.
No, you can call
Darwin done, FreeBSD/NetBSD/OpenBSD WIP. |
Progress update:
I will focus on liblsof user interface next. |
Is your feature request related to a problem? Please describe.
I'm always frustrated when the only way to extract information about open file descriptors in a system is to parse them from running
lsof
as a sub-process and filter its output. While this might be fine for single snap-shotted use, this becomes quite wasteful when trying to integrate such functionality in a system monitoring tool which could benefit from these information being presented with a sane API.Describe the solution you'd like
The collected information about open file descriptors and processes should be made available as a linkable shared library that other programs can use. This library should expose information about processes (+stats) and their open file descriptors. The library should expose functions to create snapshots of the whole system or just single processes, allow to collect information on single file, all file descriptors of a process or all of them. The library should allow to use a cache for these information so that information updates can be done incrementally (similar to the existing monitoring mode).
Describe alternatives you've considered
There is an existing feature of the
lsof
binary to run in a continuous mode. While this mode in general allows to receive updates for open file descriptors in fixed intervals it's not suitable to use when the scope of needed information changes over time (e.g. system monitor just showing number of open files per process and only needs actual file names and types once details for a particular process are requested by a user). Using a library could instruct the library which information to collect and request missing information on-demand.There's furthermore a re-implementation of
lsof
inutil-linux
with JSON as interchange format (which is at times easier to integrate with applications), but which suffers similar flexibility issues over its runtime while furthermore neither being widely available nor backwards compatible withlsof
. Thus while JSON is a nice interchange format for data (nless you have to parse it), a binary, in-process API would be much easier to work with.Additional context
The machine-readable format of
lsof
is hardly documented. In particular some parts of it are overly complicated (having to convert numbers back-and-forth between representations, when things would be unambiguous in a proper library API). Also, depending on the platform, certain attributes are not exposed consistently, leading to situations where sometimes only one of two attributes (e.g. size or offset) are available.The text was updated successfully, but these errors were encountered: