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

Fix socket to PID translation on FreeBSD. #1070

Merged
merged 1 commit into from
May 16, 2017
Merged

Fix socket to PID translation on FreeBSD. #1070

merged 1 commit into from
May 16, 2017

Conversation

glebius
Copy link
Contributor

@glebius glebius commented May 14, 2017

This file was derived from FreeBSD usr.bin/sockstat/sockstat.c. The
logic of socket to PID translation was copied incorrectly. The hash,
that sockstat(1) utility has, is completely internal feature, it isn't
part of FreeBSD API, it is just to speed things up. So, to use this
hash one actually needs to create it: declare array of buckets, populate
it with sockets. In the freebsd_socks.c this wasn't done. This fix
doesn't create the hash, instead it removes remnants of hashing that was
there in sockstat.c. It makes code more simple, but of course slower than
original sockstat(1) in case if machine is running zillions of sockets. I
decided to go this way simply because I am low on time to invest into
psutil, and also because better first provide correct and simple
implementation and then improve it, rather than jump for complexity.

This file was derived from FreeBSD usr.bin/sockstat/sockstat.c. The
logic of socket to PID translation was copied incorrectly. The hash,
that sockstat(1) utility has, is completely internal feature, it isn't
part of FreeBSD API, it is just to speed things up. So, to use this
hash one actually needs to create it: declare array of buckets, populate
it with sockets. In the freebsd_socks.c this wasn't done. This fix
doesn't create the hash, instead it removes remnants of hashing that was
there in sockstat.c. It makes code more simple, but of course slower than
original sockstat(1) in case if machine is running zillions of sockets. I
decided to go this way simply because I am low on time to invest into
psutil, and also because better first provide correct and simple
implementation and then improve it, rather than jump for complexity.
@giampaolo giampaolo merged commit 5b64638 into giampaolo:master May 16, 2017
@giampaolo
Copy link
Owner

This PR fixes the PID mismatch issue but net_connections does not return all connections, see:
#1013 (comment)

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

Successfully merging this pull request may close these issues.

2 participants