pid = fork();
if (pid == 0) {
//setsid();
test1(pid);
} else if (pid > 0)
{
printf("This is the parent process! my id=%d ,child process id = %d\n", getpid(),pid);
test(pid);
} else {
printf("fork error\n");
}
return 1;
}
gdb对子进程进行调试:
aven@dolphin-j:~> ./ctrl_c_test &
[1] 6537
This is the parent process! my id=6537 ,child process id = 6538
aven@dolphin-j:~> gdb attach 6538
GNU gdb (GDB) SUSE (7.0-0.4.16)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-suse-linux".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
attach: No such file or directory.
Attaching to process 6538
Reading symbols from /home/aven/ctrl_c_test...done.
Reading symbols from /lib64/libc.so.6...Missing separate debuginfo for /lib64/libc.so.6
Try: zypper install -C "debuginfo(build-id)=a41ac0b0b7cd60bd57473303c2c3de08856d2e06"
(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Missing separate debuginfo for /lib64/ld-linux-x86-64.so.2
Try: zypper install -C "debuginfo(build-id)=17c088070352d83e7afc43d83756b00899fd37f0"
(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
0x00007f9b618bf060 in __nanosleep_nocancel () from /lib64/libc.so.6
(gdb) c
Continuing.
^C^C^C^C^Z