I want to have a code which can share memory to a paticular variable while forking.
i know that shmget() helps in sahring memory but not clear how to use it.
Could u please help
I want to have a code which can share memory to a paticular variable while forking.
i know that shmget() helps in sahring memory but not clear how to use it.
Could u please help
> i know that shmget() helps in sahring memory but not clear how to use it
calling shmget() will give you what is called an shmid (an int). You will either create the shared memory, or will just get the shmid of an already existing shared memory already (watch carefully the options you pass to the function)
With this shmid you can attach to a memory segment by calling shmat().
shmat() will return a pointer to your memory segment.
You need these two basic steps. Then you can do whatever you want with it. Clean when you're done.
shmdt() will detach the shared memory segment
shmctl() with IPC_RMID will delete the segment.
Read the documentation of the functions for detail on the options.