I know that the stream for file descriptor 2u is stderr. However, I'm not sure what the stream for file descriptor 3u would be and why? Ultimately, what does 3u represent here?
1 Answer
Quoting the manual:
FD is the File Descriptor number of the file [...]
FD is followed by one of these characters, describing the mode under which the file is open: [...] u for read and write access;
TYPE is the type of the node associated with the file - e.g., GDIR, GREG, VDIR, VREG, etc.
or IPv4 for an IPv4 socket;
NODE is the node number of a local file; [...] or the Internet protocol type - e.g, ``TCP'';
NAME is [...] the local and remote Internet addresses of a network file; the local host name or IP number is followed by a colon (':'), the port,
->
, and the two-part remote address; IP addresses may be reported as numbers or names, depending on the +|-M, -n, and -P options; colon-separated IPv6 numbers are enclosed in square brackets; IPv4 INADDR_ANY and IPv6 IN6_IS_ADDR_UNSPECIFIED addresses, and zero port numbers are represented by an asterisk ('*'); a UDP destination address may be followed by the amount of time elapsed since the last packet was sent to the destination; TCP, UDP and UDPLITE remote addresses may be followed by TCP/TPI information in parentheses - state (e.g.,(ESTABLISHED)
,(Unbound)
), queue sizes, and window sizes (not all dialects) - in a fashion similar to what netstat(1) reports; see the -T option description or the description of the TCP/TPI field in OUTPUT FOR OTHER PROGRAMS for more information on state, queue size, and window size;
So, here lsof
tells you that file descriptor 3 of process 3932 currently running nc
is in read+write mode (u
; though that's hardly relevant for a listening socket) and is pointing to a listening IPv4 TCP socket bound to INADDR_ANY and port 1337.
That's a socket where nc
expects incoming TCP connections to land on.
When nc
was started, fds 0, 1 and 2 were already opened as those are by convention reserved for standard input, output or error, so when nc
called the socket()
system call to create that new socket, the system returned the first free file descriptor for that process: 3.
Then nc
will typically do an accept()
on that socket, and when an incoming connection comes in, the accept()
will return with another file descriptor for the accepted socket that will actually carry the transferred data. And again, that will be the first free one, so likely 4.
-
That makes a lot of sense. Thank you!user516609– user5166092022-03-02 20:22:07 +00:00Commented Mar 2, 2022 at 20:22