DHCP 产生僵尸进程【原创】

   之前在做项目时,遇到板子运行一段时间后就死掉了,查看是内存不足了,怎么引起的呢,项目代码都经过检验了,后来通过问题排查,发现系统里面有很多DHCP的僵尸进程。

    项目由于使用串口功能,所以在启动脚本把程序放到了前台运行,相当于DHCP还是在一个父进程里面,下面出问题的原因: 当DHCP获取到ip后,会创建一个新进程把自己放到后台,这时候由于还是在一个shell里面,导致父进程僵死。

    解决办法:只让它 切一次进入后台,后面再获取IP后不再创建进程。

   修改代码:

 

static void client_background(void)

{

///modify for jiangshi code by zjf 2017.08.27

    static int time = 1;

    if(time == 1)

    {

        printf("client_background... firstime.. %d times...\n", time);

#if !BB_MMU

bb_error_msg("cannot background in uclinux (yet)");

/* ... mainly because udhcpc calls client_background()

 * in _the _middle _of _udhcpc _run_, not at the start!

 * If that will be properly disabled for NOMMU, client_background()

 * will work on NOMMU too */

#else

bb_daemonize(0);

logmode &= ~LOGMODE_STDIO;

/* rewrite pidfile, as our pid is different now */

write_pidfile(client_config.pidfile);

#endif

/* Do not fork again. */

client_config.foreground = 1;

client_config.background_if_no_lease = 0;

    }

    else

    {

        printf("--------------------------->\n");

        printf("client_background..... %d times...\n", time);

        printf("--------------------------->\n");

    }

    time ++;

    if(time >= 10000)

        time = 10;

 

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值