Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何获取建立套接字的进程的 pid。我浏览了这个PDF 链接,他提到用 F_SETOWN 调用 fcntl() 和我们进程的 pid 来告诉进程它是套接字的所有者。如何使用 fcntl() 获取套接字所有者?
来自 fcntl() 的 man pagr
F_SETOWN (int) 将接收文件描述符 fd 上的事件的 SIGIO 和 SIGURG 信号的进程 ID 或进程组 ID 设置为 arg 中给出的 ID。进程 ID 指定为正值;进程组 ID 指定为负值。最常见的是,调用进程将自己指定为所有者(即,arg 被指定为 getpid(2))。
您可以使用 getpid() 来获取进程 ID。在将其传递给 F_SETOWN 时,您要求在 SD 可读或可写时通知该进程。
具体来说,您的标题问题的答案是 getpid()。