Need Help On Shared Memory Glitch

Need Help On Shared Memory Glitch

Post by Joshua We » Wed, 10 Apr 1996 04:00:00



I am writing a routine that will limit the number of processes created by using the fork() call.  I am using shared memory to hold the
maximum number of processes allowed.  I am trying to keep track of the number of processes by using the data structure associated with shared
memory:  struct shm_ds.   Inside this structure, there is a variable called "shm_nattch", which is supposed to be the number of processes
attatched to a piece of shared memory.  Each time I make a fork() call, I attatch the new child process to the shared memory, thinking that
all I have to do is make a call using shmctl() to obtain a copy of the data structure associated with the shared memory I allocated earlier.
This will allow me to check the current value of shm_nattch for the shared memory.

When I first attatch the parent process and check the number of processes attatched I get 1.  However, when I make a fork() call and attatch
the new child process, the new child process says that there are 3 processes attatched when there should only be two.  I looked more closely
and found that whenever I tried to view the number of processes attatched I read a number that was (the correct # of processes
attatched)+(previous # of process attatched).  

I am wondering if this is a bug in the operation system, or if I am misinterpreting what is going on.
This seems to be the same case on the SGI workstations also.

If anyone might have an answer, I would appreciate any information possible.  Thank you.

Joshua Week
SDSM&T