Я работаю над встроенной системой, которая запускает ядро Linux 3.14 на устройстве PowerPC.Мне нужно запустить приложение C ++, которое должно запустить системную команду и получить результат.Я пробовал с popen но зависает.Посмотрите код ниже:
#define PATH_MAX_MIO 255
...
FILE *fp;
char path[PATH_MAX_MIO];
fp = popen("ll", "r"); // It hangs here. "ll" is the linux command to view files inside a directory
if (fp == NULL){ return; }
while (fgets(path, PATH_MAX_MIO, fp) != NULL)
std::cout<< path;
pclose(fp);
С помощью отладчика я могу запустить до вызова popen, после чего он зависает, и если я запускаю команду top , я вижу, что процесс занимает почти весь процессор (изменениемежду 90% и 99,9%).
Я не могу понять, почему это происходит.Любой совет?Спасибо.
.: РЕДАКТИРОВАТЬ:. Это вывод strace -f
команды
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5348] <... select resumed> ) = 15 (in [14], left {0, 0})
[pid 5348] select(15, [], NULL, NULL, {0, 0} <unfinished ...>
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5348] <... select resumed> ) = -1 EINTR (Interrupted system call)
[pid 5348] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL, si_value={int=14594, ptr=0x3902}} ---
[pid 5348] sigreturn() (mask []) = -1 EINTR (Interrupted system call)
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, <unfinished ...>
[pid 5347] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL, si_value={int=14594, ptr=0x3902}} ---
[pid 5347] <... rt_sigprocmask resumed> [], 8) = 27
[pid 5347] syscall_671098914(0, 0x1, 0xba4bdeda, 0xcbcb28a, 0xb6f76f8c, 0xb6f76f20) = 0
[pid 5348] select(15, [14], NULL, NULL, {0, 0}) = 0 (Timeout)
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, <unfinished ...>
[pid 5348] select(15, [14], NULL, NULL, {0, 0}) = 0 (Timeout)
[pid 5347] <... rt_sigprocmask resumed> [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, <unfinished ...>
[pid 5347] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL, si_value={int=14594, ptr=0x3902}} ---
[pid 5347] <... rt_sigprocmask resumed> [], 8) = 27
[pid 5347] syscall_268774496(0, 0x10052a5c, 0x28002824, 0xb7a2f008, 0x1, 0xb7a379c0) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5348] select(15, [14], NULL, NULL, {0, 0}) = 0 (Timeout)
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, <unfinished ...>
[pid 5348] select(15, [14], NULL, NULL, {0, 0}) = 0 (Timeout)
[pid 5347] <... rt_sigprocmask resumed> [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, <unfinished ...>
[pid 5347] --- SIGPROF {si_signo=SIGPROF, si_code=SI_KERNEL, si_value={int=14594, ptr=0x3902}} ---
[pid 5347] <... rt_sigprocmask resumed> [], 8) = 27
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
[pid 5347] rt_sigprocmask(SIG_BLOCK, NULL, [], 8) = 0
Тед Люнгмо предложил запустить трассировку, которая показывает только exec* операции, результат такой:
strace -f ../runtime/Run6 2>&1 | grep -E 'exec[a-z]+\('
execve("../runtime/Run6", ["../runtime/Run6"], [/* 13 vars */]) = 0
[pid 1068] execve("/bin/sh", ["sh", "-c", "cat /proc/version"], [/* 13 vars */]) = 0
[pid 1069] execve("/bin/cat", ["cat", "/proc/version"], [/* 13 vars */]) = 0
Тогда он висит снова