博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
对pgpoo-II的pool_process_context的 proc_id 的理解
阅读量:5324 次
发布时间:2019-06-14

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

已开始,我以为:pool_process_context 里面的 proc_id是 其 进程ID。其实满不是那么回事:

看Source:

/*                                         * Child process context:                                         * Manages per pgpool child process context                                         */                                        typedef struct {                                            /*                                         * process start time, info on connection to backend etc.      */                                        ProcessInfo   *process_info;                            int proc_id;  /* Index to process table(ProcessInfo) (!= UNIX's PID) */                                                    /*                                         * PostgreSQL server description. Placed on shared memory.      * Includes backend up/down info, hostname, data directory etc.     */                                        BackendDesc *backend_desc;             int local_session_id;   /* local session id */                                                                } POOL_PROCESS_CONTEXT;

再看 pool_init_process_context

/*                                     * Initialize per process context                                     */                                    void pool_init_process_context(void){                                        process_context = &process_context_d;     if (!process_info){                                        pool_error("pool_init_process_context: process_info is not set");         child_exit(1);                                }                                    process_context->process_info = process_info;                                                                        if (!pool_config->backend_desc){                                        pool_error("pool_init_process_context: backend_desc is not set");         child_exit(1);                                }                                    process_context->backend_desc = pool_config->backend_desc;     process_context->proc_id = my_proc_id;      process_context->local_session_id = 0;     /* initialize local session counter */            }

proc_id = my_proc_id。

而 my_proc_id 来自于 main.c 中生成子进程一段:

int my_proc_id;                        /*                        * fork a child                        */                        pid_t fork_a_child(int unix_fd, int inet_fd, int id){                            pid_t pid;            pid = fork();          if (pid == 0){                            /* Before we unconditionally closed pipe_fds[0] and pipe_fds[1]          * here, which is apparently wrong since in the start up of                         * pgpool, pipe(2) is not called yet and it mistakenly closes         * fd 0. Now we check the fd > 0 before close(), expecting                         * pipe returns fds greater than 0.  Note that we cannot                         * unconditionally remove close(2) calls since fork_a_child()            * may be called *after* pgpool starting up.                         */                        if (pipe_fds[0] > 0){                            close(pipe_fds[0]);                        close(pipe_fds[1]);                    }                                                myargv = save_ps_display_args(myargc, myargv);                                                /* call child main */                        POOL_SETMASK(&UnBlockSig);                        reload_config_request = 0;                        my_proc_id = id;                        run_as_pcp_child = false;                        do_child(unix_fd, inet_fd);                    }else if (pid == -1){                            pool_error("fork() failed. reason: %s", strerror(errno));                        myexit(1);                    }                        return pid;                    }

具体来说,在 main.c的代码中,有如下一段。

/* fork the children */                                            for (i=0;i
num_init_children;i++){ process_info[i].pid = fork_a_child(unix_fd, inet_fd, i); process_info[i].start_time = time(NULL); }

所以,如果pgpool.conf中 num_init_children为128(缺省值),

那么,每个子进程的 my_proc_id 就会分别是:0,1,2...127。

也就是说,每个子进程的  process_context->proc_id 就是0,1,2,...127。

转载于:https://www.cnblogs.com/gaojian/archive/2012/08/10/2631881.html

你可能感兴趣的文章
kernel input device
查看>>
java 从网络Url中下载文件
查看>>
MySql和Hibernate中关于cascade的用法
查看>>
hdu 3033 I love sneakers! 分组背包
查看>>
windows下统计某个目录下的源代码的行数
查看>>
图论总结
查看>>
c# dynamic 类型调用静态方法实例
查看>>
Python练习题 004:判断某日期是该年的第几天
查看>>
RHCSA-day3
查看>>
7 练习1-基础练习
查看>>
学习希尔排序
查看>>
从GoogleClusterData统计每个用户的使用率、平均每次出价
查看>>
阿里云centos7搭建wordpress环境
查看>>
距离1970.1.1零时的时间,需要考虑时差的问题
查看>>
读取配置文件--AppConfig
查看>>
Nginx(Logs)
查看>>
canvas-时钟
查看>>
生成器(generator)以及利用生成器(generator)产生并行效果
查看>>
Vue初学跳坑
查看>>
Eclipse使用hibernate插件反向生成实体类和映射文件
查看>>