Example: Multiprocess Breakpoint
The following partial program illustrates the different points at which you can set breakpoints in a multiprocess program:
1 pid = fork();
2 if (pid == -1)
3 error ("fork failed");
4 else if (pid == 0)
5 children_play();
6 else
7 parents_work();
The following table shows the results of setting a breakpoint at different places.
| Line Number |
Result |
| 1 |
Stops the parent process before it forks. |
| 2 |
Stops both the parent and child processes (if the child process was successfully created). |
| 3 |
Stops the parent process if fork() failed. |
| 5 |
Stops the child process. |
| 7 |
Stops the parent process. |