在c/c++中如何然程序停住,等待debugger

使用下面的代码片断
1 . 程序的输出被重定向

char command[255];
sprintf(command, "echo pid: %d > /tmp/pid.txtn", getpid() );
system(command);
sleep(60);

在这里你需要tail -f /tmp/pid.txt来查看文件的内容是否发生了变化。
2 . 程序的输出没有被重定向

printf("pid is: %d", getpid());
getchar();

3 . 使用gdb attach pid来debug就可以了。