- 论坛徽章:
- 0
|
1. 主要是父子进程的调试问题,出现一个很奇怪的现象。在子进程中设置断点,会将子进程的弄
成defunction(僵死)的进程。然而如果在父进程的部分设置断点,就不会出现子进程僵死的问题。
好像是子进程一挂就挂死了。
int main(void)
{
pid_t pid;
/* fork the child process */
pid = fork();
if (pid < (pid_t)0)
{
printf("fork failed . \n");
exit(1);
}
if (pid == (pid_t)0)
/* 子进程 */
{
(断点在这) printf("process child before sleep. \n");
sleep(3000);
}
else {
printf("process parent before sleep. \n");
sleep(300);
}
在父进程中设置断点,父子进程都没有问题。
int main(void)
{
pid_t pid;
/* fork the child process */
pid = fork();
if (pid < (pid_t)0)
{
printf("fork failed . \n");
exit(1);
}
if (pid == (pid_t)0)
/* 子进程 */
{
printf("process child before sleep. \n");
sleep(3000);
}
else {
(断点在这) printf("process parent before sleep. \n");
sleep(300);
}
这是不是意味着用GDB调试父子进程,只能是在父子进程都运行ok的情况下,分别将gdb attach到进程上。
但是如果只想起一个gdb, 或者是子进程成功运行起来,但是马上出错,根本来不及attach,这种方法就
有问题了。不知道是不是gdb调试这种多进程的缺陷? 好像在网上看到过。
测试用的环境是这样的:
SunOS 5.7 Generic_106541-23 sun4u sparc SUNW,Ultra-4
2. 父进程被挂起,子进程是不是也被挂起来了? 至少从gdb的结果来看,不是的。 |
|