为编程爱好者分享易语言教程源码的资源网
雨云服务器 5 折购买
雨云服务器 · 5 折购买
稳定高速 · 新老用户同享 · 点击立即抢购
立即购买
AD广告招租 了解广告位详情 ›

网站首页 > 数据库 正文

PostgreSQL数据库进程——InitPostmasterDeathWatchHandle

三叶资源网 2022-08-21 21:18:50 数据库 1082 ℃ 0 评论

InitPostmasterDeathWatchHandle函数初始化仅仅一个句柄用于监控postmaster death。在postmaster中调用,这样子进程在父进程挂掉之后才能监控到(subsequently monitor)。创建postmaster_alive_fds管道,postmaster拥有管道的写端,子进程拥有管道的读端。子进程可以将读端的文件描述符传递到select中在postmaster die后唤醒,或者通过read函数返回0来检查postmaster death。子进程必须在forking之后立刻关闭该管道的写端(只有在所有子进程关闭了写端之后,EOF在read端才会有信号,EOF won’t be signaled in the read end until all processes have closed the write fd)

static void InitPostmasterDeathWatchHandle(void){

/* Create a pipe. Postmaster holds the write end of the pipe open

* (POSTMASTER_FD_OWN), and children hold the read end. Children can pass

* the read file descriptor to select() to wake up in case postmaster

* dies, or check for postmaster death with a (read() == 0). Children must

* close the write end as soon as possible after forking, because EOF

* won't be signaled in the read end until all processes have closed the

* write fd. That is taken care of in ClosePostmasterPorts(). */

Assert(MyProcPid == PostmasterPid);

if (pipe(postmaster_alive_fds) < 0)

ereport(FATAL,

(errcode_for_file_access(),

errmsg_internal("could not create pipe to monitor postmaster death: %m")));

/*

* Set O_NONBLOCK to allow testing for the fd's presence with a read()

* call.

*/

if (fcntl(postmaster_alive_fds[POSTMASTER_FD_WATCH], F_SETFL, O_NONBLOCK) == -1)

ereport(FATAL,

(errcode_for_socket_access(),

errmsg_internal("could not set postmaster death monitoring pipe to nonblocking mode: %m")));

来源:三叶资源网,欢迎分享,公众号:iisanye,(三叶资源网⑤群:806035103 )

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 你 发表评论:

百度站内搜索
关注微信公众号
三叶资源网⑤群:三叶资源网官方群:806035103

网站分类
随机tag
支付宝易语言破解版Edge浏览器MP3文件头信息易包登录拼多多滑块验证易语言客户端电脑QQ虎牙登录源码易代码编辑框文件系统对象线程池操作fiddler多线程注册Tencent模仿打字效果Fiddler拦截朗读翻译助手
最新评论
雨云服务器 · 5 折购买
稳定高速 · 新老用户同享 · 点击立即抢购
立即购买