我正在尝试在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