欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

gdb调试多进程程序

程序员文章站 2022-07-09 16:44:02
...

    1.gdb下调试多进程程序只需要以下几条命令即可
        gdb调试多进程程序
    除此之外还可以查看正在调试的进程 info inferiors, 同时也可以将当前正在调试的进程切换到另外一个进程中让其取运行
    2.代码调试演示

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

void father_process();
void child_process();

int main()
{
    pid_t pid = fork();

    if (pid < 0)
    {
        fprintf(stderr, "fork failure\n");
        exit(-1);
    }
    else if (pid > 0)
    {
        father_process();
    }
    else
    {
        child_process();
    }
    return 0;
}

void father_process()
{
    pid_t pid = getpid();
    printf("father pid = %d\n", pid);
    printf("hello world\n");
}

void child_process()
{
    pid_t pid = getpid();
    printf("child pid = %d\n", pid);
}

gdb调试多进程程序
    本字只写了多进程的调试, 后继会写出 gdb 下如何对多线程进行调试的相关文章, 如有错误, 望各位大佬及时指出