question about dbx and fork(2)

James Binkley jrb at jove.cs.pdx.edu
Sat Apr 13 01:07:09 AEST 1991


Can somebody explain why the following happened?

Take a look at the dbx session below. The code is listed.
This was done on a Sun 4.1 system.
The machine is a 68020. I set a breakpoint
on main and then "run" to it. I then singlestep past
the fork. There is a fork() where the child/inferior
loops in an infinite loop. The parent waits. The wait
returns 85 as status, meaning the child died courtesy
of a SIGTRAP plus a core file was generated.
However the breakpoint was on "main" in the parent.
I could understand this if the breakpoint had been
set in the text of the child. Apparently the child
has somehow been awarded the signal anyway.  Something
to do with virtual memory or??? 

gdb 3.5 on the same machine does not exhibit the
same behavior; i.e., wait() blocks as one would expect.
However it does exhibit the same behaviour on a Sequent 
running Dynix. 

				Jim Binkley
				jrb at jove.cs.pdx.edu

script of dbx session follows:
------------------------------------------
Script started on Thu Apr 11 20:22:48 1991
jove% dbx fork
Reading symbolic information...
Read 51 symbols
(dbx) list 1,35
    1   /*
    2    * fork.c
    3    */
    4   main()
    5   {
    6
    7           int x;
    8           int pid, status;
    9
   10           x = 1;
   11           /* parent forks child here
   12           */
   13           if ( fork() == 0) {
   14                   /* set a breakpoint here
   15                   */
   16                   x = 2;
   17                   printf("child pid is %d\n", getpid());
   18                   printf("child %d\n", x);
   19                   while (x == 2)
   20                           ;
   21                   x = x + 1;
   22                   exit(1);
   23           }
   24
   25           /* parent process waits for child to exit
   26           */
   27           pid = wait(&status);
   28
   29           /* pay attention to what is printed out here
   30           */
   31           printf("status %x\n", status);
   32           x = x + 1;
   33           printf("x %d\n", x);
   34           exit(0);
   35   }
(dbx) stop in main
(2) stop in main
(dbx) status
(2) stop in main
(dbx) run
Running: fork
stopped in main at line 10 in file "fork.c"
   10           x = 1;
(dbx) s
stopped in main at line 13 in file "fork.c"
   13           if ( fork() == 0) {
(dbx) s
stopped in main at line 27 in file "fork.c"
   27           pid = wait(&status);
(dbx) s
stopped in main at line 31 in file "fork.c"
   31           printf("status %x\n", status);
(dbx) s
status 85
(dbx) quit



More information about the Comp.unix.programmer mailing list