In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you what is the principle of linux2.6.12.1-based process sleep, the content is very detailed, interested friends can refer to, hope to be helpful to you.
A process is a dynamic entity that executes all the time when the conditions are met, but sometimes it is suspended when the conditions are not met. But this is passive, not process-controlled, that is to say, when a process accesses a resource, if it cannot be satisfied, the process will be suspended by the system, and when the conditions are met, the system will arouse the process.
What we introduce today is the ability of a process to sleep actively. That is, the process allows itself to suspend itself and wakes up by the system after a certain period of time (time is up or a signal is received). This capability is provided by the sleep function.
Unsigned int sleep (unsigned int seconds)
This function allows the process to suspend seconds seconds on its own. Let's take a look at some instructions for this function.
On Linux, sleep () is implemented via nanosleep (2). See the nanosleep (2) man page for a discussion of the clock used.
That is, the sleep function is implemented by the [nanosleep] (http://www.man7.org/linux/man-pages/man2/nanosleep.2.html) function) of the operating system. Let's take a look at the core code.
Asmlinkage long sys_nanosleep (struct timespec _ _ user * rqtp, struct timespec _ _ user * rmtp) {struct timespec t; unsigned long expire; long ret
Expire = timespec_to_jiffies (& t) + (t.tv_sec | | t.tv_nsec); current- > state = TASK_INTERRUPTIBLE; expire = schedule_timeout (expire)
}
Calculate the timeout, then suspend the process (interruptible suspension), and then call schedule_timeout.
Fastcall signed long _ _ sched schedule_timeout (signed long timeout) {struct timer_list timer; unsigned long expire; / / calculate the timeout expire = timeout + jiffies
Init_timer (& timer); / / timeout timer.expires = expire; timer.data = (unsigned long) current; / / timeout callback timer.function = process_timeout; / / add timer add_timer (& timer); / / process scheduling schedule (); / / delete timer del_singleshot_timer_sync (& timer) / / if you have timed out or been awakened by a signal, you may not have timed out timeout = expire-jiffies.
Out: return timeout < 0? 0: timeout;}
Then add a timer to the system, then send a process schedule, and the process goes into a suspended state. After a certain period of time, the process will wake up. In addition, we notice that the pending process state is TASK_INTERRUPTIBLE, which is interruptible. It means that the process in this state can be awakened by the signal. And TASK_UNINTERRUPTIBLE cannot be awakened by the signal.
When the timeout occurs, the process_timeout function is executed.
Static void process_timeout (unsigned long _ data) {wake_up_process ((task_t *) _ data);}
The code is simple enough to wake up a suspended process. _ _ data is in
Timer.data = (unsigned long) current
Set in the. This is the general principle of process active sleep (sleep).
On the principle of linux2.6.12.1-based process sleep is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.