APUE 17章高级IPC——本地转发文件表指针(什么用?)
来源:互联网 发布:己知直径求周长 编辑:程序博客网 时间:2024/06/10 13:50
Technically, we are passing a pointer to an open file table entry from one process toanother. This pointer is assigned the first available descriptor in the receiving process.(Saying that we are passing an open descriptor mistakenly gives the impression that thedescriptor number in the receiving process is the same as in the sending process, whichusually isn’t true.) Having two processes share an open file table is exactly whathappens after afork.
于是我们这里直接就叫做本地转发文件表指针以避免误解(我看到过很多不明真相的群众按字面意思理解这个,以为真就是传递了一个文件描述符)。还有一点非常重要,那就是:
Closing the descriptor by the sender doesn’t really close the file or device, since the descriptor is still considered open by the receiving process (even if the receiver hasn’t specifically received the descriptor yet).
应该是传递的时候,文件表里头引用计数被加一,哪怕接受进程没有显示地调用unix domain socket去接受这个描述符(这其实有点疑问,因为对方不接受,发送的进程就阻塞在sendmsg函数这里了)。我们转发这个文件表指针有何用呢?
1)用于进程池连接:
假设我们本地有工作进程A,B,C。每个都提供不一样的服务用于网络。我们有两种策略,一种是每个进程都是一个服务器进程,都占用不一样的端口或者地址,分离开来分别管理;另外一种是我们建立个连接服务器来管理外部连接,每次把socket 描述符转发给对应的工作进程让工作进程处理后续通讯,这样我们只要占用一个地址和端口就可以了,而且我们可以集中化管理认证各个连接。
2)用于构造类似系统调用的服务:
这个可以详见APUE里头17章open server小节。
- APUE 17章高级IPC——本地转发文件表指针(什么用?)
- apue学习第二十一天——IPC基础(第十五章)
- unix环境高级编程(第2版)——使用自定义头文件apue.h
- APUE学习笔记——第十四章 高级IO
- APUE学习笔记——第十六章 网络IPC:套接字
- apue学习笔记(第十六章 网络IPC:套接字)
- 《UNIX环境高级编程》 —— 公共头文件 apue.h
- apue.h头文件(unix环境高级编程)
- apue.h头文件(UNIX环境高级编程)
- apue.h头文件(UNIX环境高级编程)
- apue.h头文件(UNIX环境高级编程)
- apue.h头文件(UNIX环境高级编程)
- apue.h头文件(unix环境高级编程)
- UNIX 环境高级编程(一) apue.h 文件与apue.3e的安装
- APUE——文件IO
- APUE读书笔记(0.2) ——APUE源代码中的awk脚本文件
- UNIX环境高级编程——IPC
- unix环境高级编程 apue.h文件
- react & Vue.js
- JavaScript 表单验证
- 计蒜客 15500 阿里天池的新任务(简单) 题解
- [ROR] rails migration 中继承 ActiveRecord::Migration[5.1] 带版本号实现原理
- Java Web中常用的分页组件(Java端实现)
- APUE 17章高级IPC——本地转发文件表指针(什么用?)
- shell中十种实现自加的方法
- 搬寝室(HDU-1421)
- 第一次的博客,lnmp为目标,继续努力
- 动态点击修改当前dom元素背景
- JdbcTemplate系列(二)----实战CRUD
- 手工收集ADDM日志
- mybatis 学习记录(4.1)—— 级联查询(无 association 和 collection)
- NAT和路由和代理服务器