LINUX Study Notes 14 -- inter-process communication 3 shared memory
Source: Internet
Author: User
A) meaning: multiple processes share part of the physical memory. Fast access, convenient B) first create shared memory: intshmget (key_tkey, intsize, intshmflg) 1.Key: indicates the shared memory key value; 0/IPC_PRIVATEa) Key0: this is not created, however, if the shmflg is still... a) meaning: multiple processes share part of the physical memory. Fast and convenient access
B) create shared memory first: int shmget (key_t key, int size, int shmflg)
1. Key: indicates the Key value of shared memory; 0/IPC_PRIVATE
A) Key = 0: this is not created, but it is still created if shmflg is still IPC_PRIVATE.
2. Size: Size
3. Shmflg: Mark S_IRUSR | S_IWUSR
4. return value: the shared memory identifier is returned successfully;-1 is returned if a failure occurs;
5. # include , # Include , # Include , # Include
C) re-map the shared memory:
1. Int shmat (int shmid, char * shmaddr, int flag)
A) Shmid: shared storage identifier returned by the shmget function
B) Shmaddr: used to save the ing address. if it is set to 0, the system automatically finds the address and returns the value.
C) Flag: used to determine the ing address (usually 0)
D) return value: if shmaddr is set to 0, the shared memory is successfully mapped to the address in the process. if shmaddr is set to 0,-1 is returned.
2. the shared memory is mapped to different processes with different addresses.
D) clear content: after obtaining the address, you need to reset the data in this memory zone first.
1. memset (p_addr, '\ 0', 1024): reset all 1024 bytes
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.