我正在嘗試在C編寫一個程序(在Linux 64bit與GCC 4.1.2)。C程序終止
int program_instances(char *cmdname)
{
char buf[32], *ret;
char cmdbuf[512];
FILE *cmdpipe;
sprintf(cmdbuf, "/bin/ps -eo comm | /bin/grep -c '%s'",
cmdname);
cmdpipe = popen(cmdbuf, "r");
if (!cmdpipe)
{
return -1;
}
memset(buf, 0, sizeof(buf));
ret = fgets(buf, sizeof(buf), cmdpipe);
pclose(cmdpipe);
if (!ret)
{
return -1;
}
int nr = atoi(buf);
return nr;
}
試圖通過GDB但行
sprintf(cmdbuf, "/bin/ps -eo comm | /bin/grep -c '%'",cmdname);
的PROGRAMM沒有橫穿過上述線,拋線以下後,調試問題..
Executing new program: /bin/bash Error in re-setting breakpoint 1: No symbol table is loaded. Use the "file" command. [New process 2437] Executing new program: /bin/ps
請幫助我們解決這個問題。
cmdname需要多長時間?你可能會跑開cmdbuf的結尾。 –
「*請幫助我們解決此問題*」 - 哪個問題?掛起或來自gdb的消息? –
這是C,不是真正的C++,如果你添加標籤,你可能會得到更快的答案 – 111111