I'm trying to find the file descriptors for all TCP sockets of a given process, ie. given its pid, so that I can get the socket option at another process without modifying the original one.
For example, if I know the file descriptor is
s = socket(...); printf("%d\n", s);
No. You simply cannot do what you are asking.
A file descriptor is just an integer, but it refers to an open file object in a given process. That integer value in another process refers to a different, possibly unopened file object.
Without involving the
ptrace debugging API, or remote code injection, you are limited to what the kernel exposes to you via
Check out the man page for ss. If this utility can't shoe you information about a socket you desire, then nothing can.