【Linux】gdb 调试多进程

首先写一个两个进程运行的程序:

#include<stdio.h>
#include<pthread.h>
#include<errno.h>

void A_process()
{
    int i=0;
    while(1)
    {
        sleep(1);
        printf("father:%d  i=%d\n",getpid(),i);
        i++;
    }
}

void B_process()
{
    int num=0;
    while(1)
    {
        sleep(1);
        printf("child:%d  num=%d\n",getpid(),num);
        num = num+10;
    }
}

int main()
{
    pid_t pid;
    if((pid=fork())<0)
    {
        perror("fork!\n");
        return 1;
    }
    else if(pid>0)     //father process
    {
        A_process();
    }
    else if(pid==0)    //child process
    {
        B_process();
    }

    return 0;
}

1.调试多进程的设置:
这里写图片描述
2.生成可调试文件:

[lize-h@localhost 0322_JinCheng]$ gcc -g proc_debug.c -o proc
[lize-h@localhost 0322_JinCheng]$ ls
fork.c  id.c  nice.c  only_child.c  proc  proc_debug.c  test.c  T_R_S.c  zombie.c
[lize-h@localhost 0322_JinCheng]$ 

生成proc 接下来进行调试

3.调试:

(1)调试主进程,block子进程
这里写图片描述 这里写图片描述这里写图片描述这里写图片描述
(2)切换到子进程:
这里写图片描述这里写图片描述
这里写图片描述

猜你喜欢

转载自blog.csdn.net/lz201788/article/details/80072489