博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对IsUnderPostmaster变量初步学习
阅读量:5771 次
发布时间:2019-06-18

本文共 3455 字,大约阅读时间需要 11 分钟。

开始

在postmaster.c 中的  BackendStartup 中,有如下的代码:

其中定义了 IsUnderPostmaster=true。

而bgwriter 作为 postmaster 的子进程,它的 IsUnderPostmaster 也是为真。

* BackendStartup -- start backend process * * returns: STATUS_ERROR if the fork failed, STATUS_OK otherwise. * * Note: if you change this code, also consider StartAutovacuumWorker. */static intBackendStartup(Port *port){    Backend    *bn;                /* for backend cleanup */    pid_t        pid;    /*     * Create backend data structure.  Better before the fork() so we can     * handle failure cleanly.     */    bn = (Backend *) malloc(sizeof(Backend));    if (!bn)    {        ereport(LOG,                (errcode(ERRCODE_OUT_OF_MEMORY),                 errmsg("out of memory")));        return STATUS_ERROR;    }    /*     * Compute the cancel key that will be assigned to this backend. The     * backend will have its own copy in the forked-off process' value of     * MyCancelKey, so that it can transmit the key to the frontend.     */    MyCancelKey = PostmasterRandom();    bn->cancel_key = MyCancelKey;    /* Pass down canAcceptConnections state */    port->canAcceptConnections = canAcceptConnections();    bn->dead_end = (port->canAcceptConnections != CAC_OK &&                    port->canAcceptConnections != CAC_WAITBACKUP);    /*     * Unless it's a dead_end child, assign it a child slot number     */    if (!bn->dead_end)        bn->child_slot = MyPMChildSlot = AssignPostmasterChildSlot();    else        bn->child_slot = 0;#ifdef EXEC_BACKEND    pid = backend_forkexec(port);#else                            /* !EXEC_BACKEND */    pid = fork_process();    if (pid == 0)                /* child */    {        free(bn);        /*         * Let's clean up ourselves as the postmaster child, and close the         * postmaster's listen sockets.  (In EXEC_BACKEND case this is all         * done in SubPostmasterMain.)         */        IsUnderPostmaster = true;        /* we are a postmaster subprocess now */        MyProcPid = getpid();    /* reset MyProcPid */        MyStartTime = time(NULL);        /* We don't want the postmaster's proc_exit() handlers */        on_exit_reset();        /* Close the postmaster's sockets */        ClosePostmasterPorts(false);        /* Perform additional initialization and collect startup packet */        BackendInitialize(port);        /* And run the backend */        proc_exit(BackendRun(port));    }#endif   /* EXEC_BACKEND */    if (pid < 0)    {        /* in parent, fork failed */        int            save_errno = errno;        if (!bn->dead_end)            (void) ReleasePostmasterChildSlot(bn->child_slot);        free(bn);        errno = save_errno;        ereport(LOG,                (errmsg("could not fork new process for connection: %m")));        report_fork_failure_to_client(port, save_errno);        return STATUS_ERROR;    }    /* in parent, successful fork */    ereport(DEBUG2,            (errmsg_internal("forked new backend, pid=%d socket=%d",                             (int) pid, (int) port->sock)));    /*     * Everything's been successful, it's safe to add this backend to our list     * of backends.     */    bn->pid = pid;    bn->is_autovacuum = false;    DLInitElem(&bn->elem, bn);    DLAddHead(BackendList, &bn->elem);#ifdef EXEC_BACKEND    if (!bn->dead_end)        ShmemBackendArrayAdd(bn);#endif    return STATUS_OK;}

 

结束

本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/11/06/2756910.html,如需转载请自行联系原作者

你可能感兴趣的文章
如何成为一个C++高级程序员
查看>>
我的友情链接
查看>>
显式锁(第十三章)
查看>>
看linux书籍做的一些重要笔记(2011.07.03更新)
查看>>
CString、Char* ,char [20]、wchar_t、unsigned short转化
查看>>
从案例学RxAndroid开发(上)
查看>>
Redis学习手册(内存优化)
查看>>
浅尝TensorFlow on Kubernetes
查看>>
springboot系列十 Spring-Data-Redis
查看>>
excel进行矩阵计算
查看>>
基于Android平台的动态生成控件和动态改变控件位置的方法
查看>>
BOM
查看>>
iOS: Block的循环引用
查看>>
MySQL类型转换
查看>>
变量声明提升1
查看>>
sed 对目录进行操作
查看>>
移动端开发单位——rem,动态使用
查看>>
系列文章目录
查看>>
手把手教你如何提高神经网络的性能
查看>>
前端布局原理涉及到的相关概念总结
查看>>