Record the small client / server jobs with shared memory shm and multi-process fork under Linux
I put such a structure in shared memory
struct buffer_area{
char ID[MAXLINE];
char MSG[MAXLINE];
};
among them
#define MAXLINE 8192
This is how shared memory is created
shmid=shmget((key_t)MEM_KEY,sizeof(struct buffer_area*),IPC_CREAT|0666);
Then there is a problem, that is, after my MSG is assigned in one process, the value in another process is inexplicably gone. I have been distressed for a long time, and then there is a flash of light. Like me, I think it may be that the array in the structure is too large , and the shared memory is not enough. Then I changed MAXLINE to 1024 ,,,, and it was solved like this, I vomited