What is the shared memory of big data's interprocess communication?
What this article shares with you is about the shared memory of big data's inter-process communication. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article. Let's take a look at it with the editor.
Shared memory:
Data transfer between processes is the most efficient in the system v version, but it is not synchronized and mutually exclusive, so it is often used in conjunction with semaphores.
Nattch: indicates how many processes are attached to shared memory. To see its value, use the ipcs-m command
Delete key value with ipcrm-m + key value
Graphics understand shared memory:
# include
# include
1. Create a shared memory function:
Int shget (key_t key,size_t size, int shmflg* buf)
The second parameter is its size, which is generally 4k, or an integer multiple of 4096.
The third parameter is generally: IPC_CREAT | IPC_EXCL
two。 Function that destroys shared memory:
Int shmctl (int shm _ id,int cmd,int shmflg* buf)
The second parameter is generally: IPC_RMID
3. Hang on to shared memory:
Void * shmat (int shmid, const void * shmaddr, int shmflg)
4. Disassociate shared memory
Int shmdt (const void * shmaddr)
Shared memory implementation code:
/ / comm.h 1 # include 2 # include 3 # include 4 # include 5 # include 6 # define _ PATH_. "7 # define _ PROJ_ID_ 0X7777 8 # define _ SIZE_ 4096 9 int shm_create () 10 {11 key_t key=ftok (_ PATH_, _ PROJ_ID_); 12 if (key)