您的位置:首页 > 数据库

对PostgreSQL中 共享内存指针的再认识

2012-11-06 17:32 281 查看
开始

先给 shmem.c 中增加代码(用来打印全局变量 ShmemIndex)

void getmemPointer()
{
fprintf(stderr,"ShmemIndex  ShmemIndex is %ld \n", ShmemIndex);
return;
}


然后,分别在 bgwriter.c 和 walwriter.c 中,增加如下代码:

/*
* Main entry point for bgwriter process
*
* This is invoked from AuxiliaryProcessMain, which has already created the
* basic execution environment, but not enabled signals yet.
*/
void
BackgroundWriterMain(void)
{
//added by gaojian
fprintf(stderr,"BackgroundWriterMain........");
getmemPointer();
…

}


/*
* Main entry point for walwriter process
*
* This is invoked from AuxiliaryProcessMain, which has already created the
* basic execution environment, but not enabled signals yet.
*/
void
WalWriterMain(void)
{
//added by gaojian
fprintf(stderr,"WalWriterMain...........");
getmemPointer();
......
}


然后,启动运行后,出现:

[postgres@localhost bin]$ ./postgres -D /usr/local/pgsql/data
LOG:  database system was shut down at 2012-11-06 16:59:15 CST
BackgroundWriterMain........ShmemIndex  ShmemIndex is 128175904
WalWriterMain...........ShmemIndex  ShmemIndex is 128175904
LOG:  autovacuum launcher started
LOG:  database system is ready to accept connections


得出的结论是,所有的后台进程,恐怕其拥有的指向共享内存的指针,其中的地址完全相同。也就是它们都指向一个共同的共享内存。

结束
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐