[Kamailio-Devel] question regarding fork and kamailio global variables usage

Henning Westerholt henning.westerholt at 1und1.de
Wed Jan 7 16:32:43 CET 2009


On Tuesday 06 January 2009, Kalpesh Rathod wrote:
> Thanks for the reply. I have got the info I was looking for.

Hi Kalpesh,

good. :)

> > To what kind of global variables do you refer to? In the shared memory
> > the access to the data is guarded by the internal memory manager. You
> > find it in the mem/shm_mem.{c,h} files.
>
> [kalpesh] I am referring to the variables which are global by their scope,
> declared outside any function body.
>
> > > So,after fork parent and child both interprete global data differently
> > > or is there any design rule enforced that after fork no.process
> > > will be writing global data. (igonre the cleanup for a while). Will
> > > there be any any problem if I dont give child task its own copy of
> > > global variables and let them use the same copy as parent?
>
> [kalpesh] I meant:
> consider global variable is_main. The interpretation of this variable is
> different in main process and the rest of the children it forks. I am 
> looking the code into more details for other such type of global vars to 
> achieve the objective of converting processes to threads.

Ok, understand. Linux uses COW on fork(), so children basically get their own 
copy of global variables. For common access to datastructures normally the 
shared memory is used. Global variables in a module context are for example 
used for configuration parameters, which can't be changed after the start 
anymore. But at least some modules uses them also to provide certain 
functionality, so that you probably will run into some issues because of some 
unwanted sharing here.

Cheers,

Henning



More information about the Devel mailing list