c - 守护进程不工作的原因

标签 c daemon

守护进程不工作的主要原因是什么?比如,我“允许”在无限循环中放入什么?因为我有这样的无限循环:

/* The Big Loop */
    while (1) {
       readname(dirSource, dirDest, list1, list2);
       sleep(1); /* wait 30 seconds */
    }

它运行一次,但仅此而已。

这是我的读取名称方法:

void readname(DIR* dirSource, DIR* dirDest, char *list1[], char *list2[]){
sizeSource=0;
sizeDest=0;
syslog(LOG_INFO, "Start saving names of files and directories.\n");
/* save all the names of the files and directories within directory */
while ((ent = readdir (dirSource)) != NULL) {
    if(strcmp(".",ent->d_name)==0 || strcmp("..",ent->d_name)==0){
    }else{

        list1[sizeSource] = strdup(ent->d_name);       
        sizeSource++;
        if(sizeSource>=nE){break;}
    }
}
closedir(dirSource);
syslog(LOG_INFO, "Finished saving names from source directory.\n");
while((ent1 = readdir (dirDest)) != NULL) {
    if(strcmp(".",ent1->d_name)==0 || strcmp("..",ent1->d_name)==0){
    }else{
        list2[sizeDest] = strdup(ent1->d_name);
        sizeDest++;
        if(sizeDest>=nE){break;}
    }
}
closedir(dirDest);
syslog(LOG_INFO, "Finished saving names from destination directory.\n");
syslog(LOG_INFO, "Finished saving all names.\n");
mkdir("/home/ubuntu/Desktop/Test", 0700);

}

如果该方法只有 mkdir 行,则它可以正常工作,它会处于无限循环中。但是当我添加其余代码时,它只执行一次。怎么了?

最佳答案

我忘记打开 DirSource 和 DirDest

关于c - 守护进程不工作的原因,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24276126/

相关文章:

python - 如何设置守护进程在其死亡时杀死其进程组中的其他进程

daemon - 如何正确使用 log_daemon_msg、log_end_msg、log_progress_msg 编写合适的守护程序脚本?

c++ - 当应用程序成为守护进程时,Valgrind 退出

c - 向 EMC Clariion 拍摄 SCSI Reservations & Release 的程序(在 Linux 上)

用于处理完整接收的 C 套接字

c - 使用 sprintf 影响数组的内容,使用 char* 影响另一个 char 数组

c - 用 C 调整数组大小

c - 如何与 Linux tun 驱动程序交互

php - 为什么在 PHP 中使用 "lock"文件而不是仅仅计算进程数?

docker - 在 Openshift 中运行的 Docker 容器中安装并运行 docker