In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "parallel Shell script how to verify Linux mutex semaphore", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "parallel Shell script how to verify Linux mutex semaphore" this article.
The use of mutex semaphores under 1 Linux
1) the function of mutex semaphores under Linux
Mutex semaphores are mainly used to ensure the atomicity of the operation when accessing shared resources, that is, the action of a whole is not allowed to be interrupted.
2) the learning method of file operation function under Linux
Man command to learn the use of functions, write a small code, the function will be used.
Let's learn about the functions related to mutex semaphores, then concatenate these functions with code, and verify them with parallel scripts.
The correlation function of mutex semaphore under 2 Linux
1) ftok function
The ftok function is used to construct key values.
① function prototype.
Key_t ftok (char * fname, int id)
② header file.
Include include
③ parameter.
Fname: a numerical representation of a file name in the kernel.
Id: project id number.
The key value is generated by a combination of fname and project id number.
④ returns a value.
Success: returns the resulting key value.
Failed:-1.
2) semget function
The semget function is used to create an open semaphore.
① function prototype.
Int semget (key_t key,int nsems,int semflg)
Gets the identifier of the semaphore collection.
When the semaphore specified by key does not exist and IPC_CREAT is included in the semflg, a semaphore set is created.
② header file.
Include
③ parameter.
Key: key value.
Semflay: flag, you can go to IPC_CREAT, corresponding to the key value of the semaphore can also be created if it does not exist.
Nsems: the number of semaphores contained in the semaphore collection created.
④ returns a value.
Success: returns the identifier of the semaphore collection.
Failed:-1.
3) semctl function
The semctl function performs various control operations on a semaphore set or a single semaphore in a set.
① function prototype.
Int semctl (int semid, int semnum, int cmd,.../* union semun arg*/)
② header file.
Include include
③ parameter.
Semid: the identifier of the set of semaphores to control.
Semnum: used to identify specific semaphores in the collection.
Cmd: specifies the action to be performed.
The semaphore parameters are enumerated as follows:
Union semun {int val; / / SETVAL value struct semid_ds * buf; / / IPC_STAT, IPC_SET buffer unsigned short * array; / / GETALL, SETALL value struct seminfo * _ buf; / / IPC_INFO buffer}
The semaphore set structure is as follows:
Struct semid_ds {struct ipc_perm sem_perm; / / permission time_t sem_otime; / / time of last semop time_t sem_ctime; / / time of last modification unsigned long sem_nsems; / / number of semaphores in semaphore set}
The parameters are described below.
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.