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 :
- 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.
- multproc parent -> This option will make dbx to follow the parent path only.
- multproc child -> This option will make dbx to follow the child path only.
- 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
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());
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);
exit(0); /* parent exits */
else /* fork returns -1 on failure */
Here, I’ll show the usage of multproc with 2 examples :
- With ‘multproc child’ option where only the child process is debugged.
- 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
 stop in main
(dbx) multproc child >>>>>>>>>>>> set dbx to follow the child process path only
(dbx) r >>>>>>>>>>>> start to execute the program
 stopped in main at line 9
9 printf(“Before forking child\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)
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 */
stopped in main at line 18
18 printf(“child: pid = %d process started.\n”, getpid());
child: pid = 8519808 process started.
stopped in main at line 19
19 printf(“child: ppid = %d.\n”, getppid());
child: ppid = 4849752.
stopped in main at line 20
20 printf(“child: Exiting.\n”);
stopped in main at line 21
stopped in _exit at 0xd0185fdc
0xd0185fdc (_exit) 81820a88 lwz r12,0xa88(r2)
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.
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
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
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.
C program (5)
Device Drivers (5)
Flash Caching (1)
Kernel Extension (3)
Subscribe to Blog via Email
Google Analytics Statsgenerated by GADWP
- pretty print symbols in AIX with kdb, KDBSYM, pr August 13, 2016
- Configure SAS controller/disk for use in AIX/VIOS partition May 15, 2016
- Enhanced num_cmd_elems attribute for virtual FC ( NPIV ) AIX March 19, 2016
- Shared Storage Pool v5 enhancements December 7, 2015
- Disk level validation for LPM of NPIV LPAR December 4, 2015