GDB调试-多进程

一、gdb常用命令

二、GDB与多进程

#include<stdio.h>
#include<sys/types.h>
#include<stdlib.h>

int main()
{
    pid_t id = fork();
    if(id < 0 )
    {
        perror("fork");
        exit(-1);
    }else if(id == 0)
    {
        printf("child id is %d, my father id is %d\n", getpid(), getppid());
    }else
    {
        sleep(1);
        printf("father id id %d\n", getpid());
        wait(NULL);
    }
    return 0;
}

默认设置下,在调试多进程程序时GDB只会调用主进程,但是GDB(>V7.0)支持多进程的分别与同步调试。即GDB支持同时调试多个进程。只需要设置follow-fork-mode(默认为 parent)和detach-on-fork(默认为:on)即可。

follow-fork-mode    detach-on-fork       说明

       parent                     on                 只调试主进程(GDB默认)

       child                        on                 只调试子进程

       parent                     off                 同时调试两个进程,gdb跟主进程,子进程block(阻塞)在fork位置

       child                        off                 同时调试两个进程,gdb跟子进程,主进程block在fork位置

设置方法: set follow-fork-mode[parent|child]      set detach-on-fork[on|off]

显示:show follow-fork-mode        show detach-on-fork

查询正在调试的进程:info    inferiors

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值