The name of the device can be obtained from
root@localhost:~ # cat /proc/22746/fdinfo/5
So you should be able to obtain the device name like this:
grep -oP '^iff:\s*\K.*' /proc/"$PID"/fdinfo/5
grep to display only the matched substring instead of the entire line.
\K in a Perl-compatible regular expression (
-P) is a kind of lookbehind assertion. The part before
\K is used for matching the string, but is not included in the string returned from the match, so you get just "tun0" without the leading "iff:".
I think the
tundevice is always file descriptor 5. Otherwise you need to enumerate the files under
/proc/$PID/fdinfo and pick the one with the
tun device entry.
Beware that the
fdinfo subdirectories have 0600 permissions, so they're only accessible by the process owner. For VPN processes that means you need root privileges, so you must run the command via
sudo or similar.