标签:InitPostmasterDeathWatchHandle postmaster death end read Postmaster pipe write P
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")));
标签:InitPostmasterDeathWatchHandle,postmaster,death,end,read,Postmaster,pipe,write,P 来源: https://blog.csdn.net/asmartkiller/article/details/122010867
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。