Disclaimer : All the postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
This post is part of the “Learn debugging using AIX DBX” series. It talks of the tips while debugging a multi-process program with AIX DBX. If you looking for some other aspect of debugging with AIX DBX go to the parent topic or other sub-topics here : http://www.sangeek.com/day2dayunix/2013/08/learn-debugging-using-aix-dbx/

The DBX command which specifies the behaviour of multi-process debug program is ‘multproc‘. The various settings for this command are :

  1. multproc on             -> This option will create a new dbx session(terminal) to debug the child path of a fork.  The original dbx will continue to debug the parent path.
  2. multproc parent  -> This option will make dbx to follow the parent path only.
  3. multproc child  -> This option will make dbx to follow the child path only.
  4. multproc off    ->  This option disables multi-process debugging.

I’ll show more details of how these options can be used with a sample multi-process program : fork_test.c

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

int main()
    pid_t childpid;
    int status;

    printf(“Before forking child\n”);

    /* create new process */
    childpid = fork();

    if (childpid >= 0)
        if (childpid == 0) /* child process */
            printf(“child: pid = %d process started.\n”, getpid());
            printf(“child: ppid = %d.\n”, getppid());
            printf(“child: Exiting.\n”);
        else /* parent process */
            printf(“parent: pid = %d.\n”, getpid());
            printf(“parent: Wait for child to exit.\n”);
            printf(“parent: Child exited with status = %d.\n”, status);
            printf(“parent: Exiting.\n”);
            exit(0);  /* parent exits */
    else /* fork returns -1 on failure */
        perror(“fork failed”);

Here, I’ll show the usage of multproc with 2 examples :

  1. With ‘multproc child’ option where only the child process is debugged.
  2. With ‘multproc on’ option where both the parent and child process can be debugged at the same time in separate terminals.


Example 1 : Following the child-process using ‘multproc child‘ while debugging the above program :

# dbx ./fork_test
Type ‘help’ for help.
reading symbolic information …
(dbx) st in main                                                                                >>>>>>>>>>>> set a breakpoint in “main” function of the program
[1] stop in main
(dbx) multproc child                          >>>>>>>>>>>> set dbx to follow the child process path only
(dbx) r                                                                                                        >>>>>>>>>>>> start to execute the program
[1] stopped in main at line 9
    9       printf(“Before forking child\n”);
(dbx) n
Before forking child
stopped in main at line 12
   12       childpid = fork();                                           >>>>>>>>>>>> After execution of this statement the program will fork a child
application forked, child pid=8519808, process stopped, awaiting input
debugging child, pid=8519808, process stopped, waiting input
parent: pid = 4849752.
parent: Wait for child to exit.                                         >>>>>>>>>>>> After fork the parent process continues, without the control of dbx, while the child process is controlled by dbx
stopped in __fork at 0xd022c2fc
0xd022c2fc (__fork+0x11c) 80410014         lwz   r2,0x14(r1)
(dbx) n
stopped in main at line 14
   14       if (childpid >= 0)
(dbx) n                                                                                                         >>>>>>>>>>>> Continue debugging the child process in dbx
stopped in main at line 16
   16           if (childpid == 0) /* child process */
(dbx) n
stopped in main at line 18
   18               printf(“child: pid = %d process started.\n”, getpid());
(dbx) n
child: pid = 8519808 process started.
stopped in main at line 19
   19               printf(“child: ppid = %d.\n”, getppid());
(dbx) n
child: ppid = 4849752.
stopped in main at line 20
   20               printf(“child: Exiting.\n”);
(dbx) n
child: Exiting.
stopped in main at line 21
   21               exit(0);
(dbx) n
stopped in _exit at 0xd0185fdc
0xd0185fdc (_exit)    81820a88         lwz   r12,0xa88(r2)
(dbx) n
program is not active                                                                      >>>>>>>>>>>> Once we have completed stepping through the child process, the waiting parent process gets the exit status
(dbx) parent: Child exited with status = 0.
parent: Exiting.

program is not active

Example 2 : Following both the child and parent process using ‘multproc on‘ while debugging the above program :

To debug both the parent and child process you need to set up a vncsession to the AIX system where the program is being debugged. You can get more details on setting up and using VNC on AIX here : https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/Power+Systems/page/How+to+install,+configure+and+use+VNC+on+AIX+V5.3

Screenshots of VNC session used to debug the example at various stages will show the usage :

1. Starting dbx on the test-program ‘fork_test’ setting ‘multproc on’ to debug both parent and child

Screenshot from 2013-08-22 16:15:10


















2. As soon as the parent program forks; dbx creates one more xterm named ‘DBX <pid>’, where <pid> is the process id of the child process

Screenshot from 2013-08-22 16:15:53





















3. We can continue debugging with either the child or parent process, as required. This will also help to recreate certain synchronization bugs or other scenarios, as well.

Screenshot from 2013-08-22 16:17:19






















What do you think ?

Set your Twitter account name in your settings to use the TwitterBar Section.
%d bloggers like this: