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

本文通过自制的bgwriter.c文件及配套头文件和函数,演示了如何通过发送SIGHUP信号来改变进程内部变量BgWriterDelay的值,以此模拟背景写入器(bgwriter)进程对外部信号的响应。

我用例子来说明:只是一个模拟,我自己做的 假的 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]#

结束:

转载于:https://www.cnblogs.com/gaojian/archive/2012/10/31/2747388.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值