I am trying to share some memory with another forked + execed process using shmget and shmat :
char test[]="test"; int shID; char *shptr; key_t shkey = 2404; shID = shmget(shkey, sizeof(char)*(strlen(test)+1), IPC_CREAT | 0666); if (shID >= 0) { shptr = shmat(shID, 0, 0); if (shptr==(char *)-1) { perror("shmat"); } else { memcpy(shptr, &test, strlen(test)+1); ....
This works great.
The fact is that test[] will be a huge char* . Therefore, I liked to easily share text[] instead of copying it. Is there a better way to handle this?
source share