首页 > 解决方案 > accept4 中的声明 {sa_family=AF_UNIX} 和 [110->2] 是什么意思?

问题描述

我在我的 android 中做了一个 strace,我得到了以下行

accept4(8<UNIX:[246]>, {sa_family=AF_UNIX}, [110->2], 0) = 9<UNIX:[2512219]>

我不明白 {sa_family=AF_UNIX} 做了什么(它应该是一个 sockaddr 指针,但它在路径和内存地址方面指向哪里?)我想知道 110 和 2 的含义以及为什么 110 是指向 2 以及此操作返回的确切内容。

(我真的很好奇这样创建的套接字的对等点,因为我在任何 proc/PID/fd 文件中都找不到 inode 2512219 所以我想知道读/写套接字的进程是否已经死了现在,如果我能知道他的名字。)谢谢!

标签: clinux-kernel

解决方案


来自man accept4

int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);

accept4(8<UNIX:[246]>, {sa_family=AF_UNIX}, [110->2], 0) = 9<UNIX:[2512219]>
  • 8sockfd价值。来自男人:the listening socket, sockfd
  • 2468文件描述符的 inode 编号
  • 指针指向的内存中存储的结构体.sa_family中的结构体成员的值为struct sockaddraddrAF_UNIX
  • 来自男人:[addr] It is filled in with the address of the peer socket, as known to the communications layer
  • 110输入值addrlen(指针指向socklen_t的内存中存储的整数addrlen)。来自男人:the caller must initialize it [addrlen] to contain the size (in bytes) of the structure pointed to by addr;
  • 2addrlen函数返回后的值。来自男人:will contain the actual size of the peer address
  • 0标志flags。来自男人:If flags is 0, then accept4() is the same as accept().
  • 9返回的文件描述符。来自男人:a nonnegative integer that is a file descriptor for the accepted socket
  • 25122199第文件描述符的 inode 号

推荐阅读