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 > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What is the cooperative process in linux? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.
Collaborative process definition
The cooperative program is a kind of lightweight thread in the user mode, and the scheduling of the cooperative program is completely controlled by the user. The co-program has its own register context and stack. When scheduling and switching, the register context and stack are saved somewhere else, and when it is switched back, the previously saved register context and stack are restored, while the direct operation stack has almost no kernel switching overhead, and the global variables can be accessed without locking, so the context switching is very fast. Linux protocol is a lightweight user-mode thread, and the operating system is not aware of it. The cooperative program implements collaborative scheduling (non-preemptive scheduling), that is, the cooperative program switching is controlled by the current cooperative program and actively gives up the CPU. Typically, a thread contains multiple collaborators.
Co-program, also known as lightweight thread, each has its own stack, it can be considered that a co-program is a function and the stack that stores the run-time data of this function, this stack is very small, generally only dozens of kb.
The characteristics of the cooperative process
1. A cooperative program is a multitasking system that runs concurrently, which is generally driven by an operating system thread.
2. The resource consumption of collaborative task metadata is lower than that of operating system threads, and the task switching overhead is small.
3. The cooperative process is a collaborative scheduling between tasks, that is, one task actively gives up execution and schedules another task to run.
For example:
While (1) {
Int nfds = epoll_wait (epoll_fd, events, curfds,-1)
If (nfds =-1) {
Perror ("epoll_wait")
Break
}
For (I = 0 * * I < nfds;i + +) {
Int sockfd = listenfd (events [I] .data.fd, sockfds)
If (sockfd) {
Socklen_t len = sizeof (struct sockaddr_in)
Int clientfd = accept (sockfd, (struct sockaddr*) & remote, & len)
Pthread_t thread_id
Pthread_create (& thread_id, NULL, client_cb, & clientfd)
}
Else
{
...
}
} is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
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.