Skip to content
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

Is it possible to get the relation between process & socket by using netlink #217

Open
asdfsx opened this issue Jul 30, 2024 · 2 comments
Open

Comments

@asdfsx
Copy link

asdfsx commented Jul 30, 2024

I'm working on netflow monitoring, and try to get the relation between process and socket.
First I tried to use fsnotify to monitor /proc/pid/fd, so I can be notified when socket is created by a specific process
but I failed cause the lib doesn't support to monitor /proc
So I try to do the same thing by using netlink.
Is it possible to get the relation between process & socket by using netlink?

@asdfsx asdfsx changed the title Is it possible to monitor /proc/pid/fd by using netlink? Is it possible to get the relation between process & socket by using netlink Jul 30, 2024
@florianl
Copy link
Contributor

florianl commented Aug 2, 2024

To my knowledge the netlink subsystem of the Linux kernel is not aware of the concept of processes. A connecting bit could be inodes (if you can match an inode to a process), that can be fetched via NETLINK_SOCK_DIAG.

@asdfsx
Copy link
Author

asdfsx commented Aug 5, 2024

@florianl I think I can match an inode to a process by scanning /proc/{pid}/fd. But the problem is sometimes the inode removed as soon as the socket closed, while I haven't finish scanning the /proc/{pid}/fd. So I want tried to use fsnotify, hope it can send a notify when /proc/{pid}/fd changed. But fsnotify doesn't support monitoring /proc. Maybe I should use inotifywait instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants