Subject: Dumb question regarding fork()d processes
To: #List NetBSD current users <current-users@NetBSD.ORG>
From: Paul Goyette <>
List: current-users
Date: 08/18/1999 19:51:04
I just ran into this problem, and wondered whether it was working
correctly or if it's a bug.  The original code is part of the amanda
backup package, amcheck.c, but what it basically does is:

1. malloc() some memory, store pointer to it in a char *msg
2. fork process 1, which does some stuff, and overwrite the stuff
   that *msg points to
3. fork process 2, which attempts to use contents of *msg
4. main() then waits for both subprocesses to finish.

What actually happened is that when subprocess 1 overwrites the
memory block pointed to by *msg, both the main process and the
subproccess 2 see the new value!

I thought that when you did a fork(), the new process was supposed to
get its _own_ copy of the original process's address space.  But in this
situation, it seems that all three processes are sharing the _same_ copy
of the malloc()d data structure!

Also, this just started happening after I updated from 1.4C to 1.4J
(-current as of Saturday 8/14/99);  prior to that, everything worked
just fine!

|   Paul Goyette  | PGP DSS Key fingerprint:  | E-mail addresses:     |
| Network Engineer|  BCD7 5301 9513 58A6 0DBC |    |
| & kernel hacker |  91EB ADB1 A280 3B79 9221 | |