I sometimes come upon machine with tap interfaces (eg, when KVM is running). How can I know which process is attached to the TAP interface?
This got me wondering and I had a look at the Linux kernel source (I'm assuming your question is about Linux).
It appears the answer's more difficult than you'd expect. This TUN/TAP API tutorial page offers some insight. Basically, your program allocates a new TUN/TAP device by opening
There are two catches here:
In practice, I suspect 2 doesn't happen much. Checking out an
There are oblique ways of solving the underlying problem. For OpenVPN, I use a tunnel setup script that names the
Each file descriptor has a /proc/pid/fdinfo/num entry, like:
So, with the interface name, you can get the pid with: