dynamic shared memory

Hi
I need help regarding shared memory. I need to maintain the following structure in shared memory.

    struct linked\_list_header\{
                     pid_t      pid;
                     pthread\_mutex_t lock;
                     int       top;
                     int       end;
                     int       free;
                     NODE   *ptr
   \}
   The node structure is as follows
   struct NODE \{
                int  index;
                int  prv;
                int  nxt;
                void *buffer;
    \}

Is it possible to maintain this dynamic linked_list_header in shared memory. I tried to maintain the same BUT I am not able to share the NODE structre data among the processes.

Thanks a lot

If you called malloc to create linked_list_header->ptr, then the address returned by malloc is private to the calling (the process that calls malloc) process. Same with NODE->buffer. You will have to allocate these things in shared "by hand" without calling malloc.

Thanks a Jim
I corrected my program to share the memory instead of malloc, Now it is working fine. I need another clarification regarding the same.

    During run time, If I need more shared memory, Is it possible to mmap the increased size of dynamic memory while retaining the contents of previously mmaped memory. \( like realloc's functionality which preserves previously allocated memory contents\)

Thanks once again

You mmap a second memory area. However mmap is not like malloc or realloc.
It works using pages of memory, not bytes. Create a really large memory block to start with. It sounds like you're using Linux.

Linux supports system V IPC XPG4.2 calls:

sys/shm.h provides support for shmat(), shmget(), etc.. You may also want to look at those calls.