对IsUnderPostmaster变量初步学习
2012-11-06 14:24
218 查看
开始
在postmaster.c 中的 BackendStartup 中,有如下的代码:
其中定义了 IsUnderPostmaster=true。
而bgwriter 作为 postmaster 的子进程,它的 IsUnderPostmaster 也是为真。
结束
在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 int BackendStartup(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; }
结束
相关文章推荐
- 学习笔记----差分约束系统初步 POJ 2983 Is the Information Reliable?
- nginx变量学习初步-读章亦春的博客做个笔记
- 20180301:JavaScript的初步学习,JS的数据类型与变量,函数,DOM操纵HTML,BOM操作浏览器
- Swift的初步学习第一步——变量的声明和set,get,?,!,别名
- C语言学习7 :二级指针定义,强制转换,多级指针初步,6级指针构造,错误应用*p=&a,错误应用 二级p2,void型指针的兼容性,malloc函数基本用法,malloc分配空间和堆栈空间的区别,验证malloc函数内存的分配,验证malloc函数的越界,内存泄漏,指针不能返回局部变量地址,内存分配
- PL/SQL学习笔记-常量变量及数据类型初步
- spring初步学习---注入配置文件变量
- 初步学习“C#中is,as用法”
- 从零开始前端学习[48]:js中的变量和this的初步认识
- Python学习笔记(8)-变量、地址、id、is与==
- 初步学习“C#中is,as用法”(转载)
- smarty模板初步学习(smarty模板文件中,开始符、结束符 与变量之间不能有空格)
- 2015.4.28类、对象的初步学习(构建类,成员变量、方法的调用)
- 初步学习“C#中is,as用法”
- PL/SQL学习笔记-常量变量及数据类型初步
- JAVA初步学习--环境变量
- PHP新手 学习变量和常量
- JavaScript 学习(一):变量(未完成)
- Python学习-5.Python的变量与数据类型及字符串的分割与连接
- php 学习笔记 —— 全局变量 魔术变量 (三)