In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
# include
Int shmget (key_t key,size_t size,int oflag); returned: shared memory object for success, error is-1
The value of key can be the return value of ftok or IPC_PRIVATE.
Ftok () is an unrelated process
IPC_PRIVATE is a consanguineous process
Size specifies the size of the memory area in bytes. When the actual action is to create a new shared memory area, you must specify a size value that is not 0. If the actual operation is to access an existing shared memory area, then size should be 0. 0.
Oflag is a collection of read and write permission values, and can also be IPC_CREAT or IPC_CREAT | IPC_EXCL
Void* shmat (int shmid, const void*shmaddr, int flag); returned: success is the starting address of the mapping area, error is-1
Shmid is the identifier returned by shmget.
If the shmaddr is a null pointer, the system selects the address for the caller. This is the recommended method.
If shmaddr is a non-null pointer, the return address depends on whether the caller has specified a SHM_ RND value for the flag parameter:
If no SHM_RND is specified, the corresponding shared memory area is attached to the address specified by the shmaddr parameter
If SHM_RND is specified, the corresponding shared memory area is attached to the address specified by the shmaddr parameter to round down a SHMLBA constant. LBA stands for "bottom boundary address".
Int shmdt (const void* shmaddr); returned: success 0, error-1
When a process terminates, all shared memory areas to which it is currently attached are automatically disconnected. This function call is not to delete the specified shared memory area.
Int shmctl (int shmid,int cmd, struct shmid_ds* buff); returned: success is 0, error is-1
Cmd has three commands:
IPC_RMID removes the shared memory area identified by shmid from the system and removes it.
IPC_SET sets the following three members of its shmid_ds structure to the specified shared memory area: shm_perm.uid, shm_perm.gid, and shm_perm.mode, whose values come from the corresponding members in the structure pointed to by the buff parameter. The value of shm_ctime is also replaced with the current time.
IPC_STAT (through the buff parameter) returns the current shmid_ds structure of the specified shared memory area to the caller.
Example:
# include#include#include#include#includeint main (int argc,char* argv []) {key_t key = ftok (argv [1], 1); if (- 1 = key) {perror ("ftok err\ n"); return 1;} int shmid = shmget (key,atoi (argv [2]), IPC_CREAT | 0644); if (- 1 = = shmid) {perror ("shmget err\ n"); return 1 } printf ("shmid:%d\ n", shmid); void* buf = shmat (shmid,NULL,0); if ((void*)-1 = = buf) {perror ("shmat err\ n"); return 1;} strcpy (buf, "hello shmat\ n"); printf ("buf:%s\ n", buf); shmdt (NULL); shmctl (shmid,IPC_RMID,NULL); return 0;}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.