C语言使用popen循环调用lua产生很多僵尸进程

僵尸进程:

11063 root         0 Z    [sh]
11068 root         0 Z    [sh]
11072 root         0 Z    [sh]
11075 root         0 Z    [sh]
11078 root         0 Z    [sh]
11080 root         0 Z    [sh]
11082 root         0 Z    [sh]
11084 root         0 Z    [sh]

解决:

popen之后添加signal(SIGCHLD, SIG_IGN);需要包含#include <signal.h>

#include <stdio.h>
#include <signal.h>
#include <string.h>

int main(int argc, char *argv[])
{
    char payload[1024] = {0};
    FILE *fp;
    fp = popen("exec /usr/bin/lua /tmp/abc.lua", "r");
    signal(SIGCHLD, SIG_IGN);
    if (NULL == fp)
        return -1;

    fgets(payload, 1024, fp);
    if (payload[strlen(payload) - 1] == '\n')
    {
        payload[strlen(payload) - 1] = '\0';
    }
    fclose(fp);
}

参考:https://www.codeleading.com/article/82835694707/

上一篇:【踩坑专栏】无法创建appender: Could not create an Appender of type [net.logstash.logback.appender...


下一篇:KubeEdge的云边协同设计原理