我正在尝试通过system()函数获取从c守护程序启动的bash脚本的返回值。如果skeleton_daemon被注释,则输出正确为5120(20 int main (void){ skeleton_daemon(); printf("%d", system("/tmp/prova.sh") ); // prova.sh return 20}void skeleton_daemon(void){pid_t pid;pid = fork();if (pid < 0) exit(EXIT_FAILURE);if (pid > 0) exit(EXIT_SUCCESS);signal(SIGCHLD, SIG_IGN);signal(SIGHUP, SIG_IGN);umask(0);// chdir("/"); // commented as per nos suggestion, nothing changed}有人知道如何从守护进程中获取脚本值吗?编辑:按要求由strace -f运行老实说我什么都不懂execve("./pr", ["./pr"], [/* 17 vars */]) = 0brk(0) = 0xd79000uname({sys="Linux", node="alarm", ...}) = 0mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f80000access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3fstat64(3, {st_mode=S_IFREG|0644, st_size=30110, ...}) = 0mmap2(NULL, 30110, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6f53000close(3) = 0open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\370\203\1\0004\0\0\0"..., 512) = 512fstat64(3, {st_mode=S_IFREG|0755, st_size=1541182, ...}) = 0mmap2(NULL, 1262984, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6e1e000mprotect(0xb6f45000, 32768, PROT_NONE) = 0mmap2(0xb6f4d000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x127000) = 0xb6f4d000mmap2(0xb6f50000, 9608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb6f50000close(3) = 0mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6f7f000set_tls(0xb6f7f4c0, 0xb6f7fba8, 0xb6f82000, 0xb6f7f4c0, 0xb6f82000) = 0mprotect(0xb6f4d000, 8192, PROT_READ) = 0mprotect(0xb6f81000, 4096, PROT_READ) = 0munmap(0xb6f53000, 30110) = 0clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb6f7f068) = 7344exit_group(0) = ?+++ exited with 0 +++提前致谢 (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 发生这种情况是因为您的skateline_daemon()函数会忽略SIGCHLD,但是system()调用假定它不会被忽略,因此它可以适当地等待,直到执行的程序完成。 (adsbygoogle = window.adsbygoogle || []).push({}); 10-08 02:50