我对bgwriter.c 与 guc 关系的初步理解

我用例子来说明:只是一个模拟,我自己做的 假的 bgwriter.c

[root@localhost test]# cat bgwriter.c

#include<stdio.h>

#include<stdlib.h>

#include<signal.h>

#include "bgwriter.h"

#include "guc.h"

//some conditions make it change, eg:signal

int BgWriterDelay=100;

void sighandler(int sig);

int main()

{

 

  signal(SIGHUP,sighandler);

  for (;;)

  {

    sleep(1);

  }

}

void sighandler(int sig)

{

  changeDelay();

  fprintf(stderr,"BgWriterDelay is now %d.\n",BgWriterDelay);

  //here I just want to demo, so close it

  exit(0);

}

[root@localhost test]#

/////////////////////////////////////////////////////////////////

下面的 "bgwriter.h" and "guc.h" and "guc.c",也都是假的。只是为了模拟。
///////////////////////////////////////////////////////////////// [root@localhost test]# cat bgwriter.h extern int BgWriterDelay; [root@localhost test]# [root@localhost test]# cat guc.h extern void changeDelay(); [root@localhost test]#cat guc.c #include "bgwriter.h" void changeDelay() { //to simulate reading configuration file etc. BgWriterDelay=500; } [root@localhost test]# ///////////////////////////////////////////////////////////////// 给 SIGHUP 信号 [root@localhost test]# gcc bgwriter.c guc.c -o bgwriter.o [root@localhost test]# ./bgwriter.o [root@localhost ~]# ps -ef|grep bgwriter.o root 5475 5297 0 15:08 pts/6 00:00:00 ./bgwriter.o root 5500 5479 0 15:08 pts/7 00:00:00 grep bgwriter.o [root@localhost ~]# kill -s SIGHUP 5475 [root@localhost ~]# BgWriterDelay is now 500. [root@localhost test]#

结束:

你可能感兴趣的:(Writer)