Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the principle of how to awaken sleep in linux0.11 process

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze the principle of sleep awakening in linux0.11 process? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

The sleep of the process is by calling the sleep_on function, which modifies the state of the process and switches to other processes to execute through the schedule function, thus realizing the suspension of the process. The process in the TASK_UNINTERRUPTIBLE state can only be awakened by the wake_up function. Processes in TASK_INTERRUPTIBLE state can be awakened by wake_up and signals. Wake up is also by changing the state of the process to runnable, and then waiting for the next process scheduling, the awakened process may not be executed immediately.

}

/ / the current process is mounted to the sleep queue p, which points to the address of the queue header pointer

Void sleep_on (struct task_struct * * p)

{

Struct task_struct * tmp

If (! P)

Return

If (current = & (init_task.task))

Panic ("task [0] trying to sleep")

/ *

* p is the address of the first sleep node, that is, tmp points to the first sleep node

The header pointer points to the current process, and this version of the implementation is not in the form of a real linked list

It forms a linked list of temporary variables in the stack of each process, each sleeping process.

There is a variable in the stack that points to the next sleep node, and then points the header pointer of the linked list to the current process.

Then switch to another process to execute, and when awakened by wake_up, wake_up wakes up the first part of the list

Sleep node, because the address of the latter node is saved in the first node, so he wakes up the latter node.

The latter node, and so on, wakes up the nodes of the entire linked list, and the implementation here is similar to nginx's filter

That is, each module saves the address of the next node, and then points the global pointer to itself.

, /

Tmp = * p

* p = current

/ / uninterruptible sleep can only be awakened by wake_up, even if there is a signal.

Current- > state = TASK_UNINTERRUPTIBLE

Schedule ()

/ / Wake up the back node

If (tmp)

Tmp- > state=0

}

Void interruptible_sleep_on (struct task_struct * * p)

{

Struct task_struct * tmp

If (! P)

Return

If (current = & (init_task.task))

Panic ("task [0] trying to sleep")

Tmp=*p

* p=current

/ *

Interruptible sleep, can be awakened by wake_up and received signals, uninterruptible

When you wake up, you can be sure to wake up one by one from the back, but interruptable sleep cannot guarantee this.

Because the process may be awakened by a signal, you need to determine whether the global pointer is pointing to itself, that is, inserting itself

After the linked list, is there any other process that inserts the linked list?

, /

Repeat: current- > state = TASK_INTERRUPTIBLE

Schedule ()

/ *

Here is true, which means that the signal wakes up, because wake_up ensures that it is the first node that wakes up.

Here, we first wake up the nodes in the linked list that are inserted after the current process. It is a bit strange that I was awakened by the signal.

To awaken other processes while still sleeping.

, /

If (* p & & * p! = current) {

(* * p) .state=0

Goto repeat

}

/ / the principle similar to sleep_on

* p=NULL

If (tmp)

Tmp- > state=0

}

/ / Wake up the first node in the queue and clear the linked list, because the first node wakes up the other nodes backwards

Void wake_up (struct task_struct * * p)

{

If (p & * p) {

(* * p) .state=0

* p=NULL

}

}

This is the answer to the question on how to analyze the principle of sleep awakening in the linux0.11 process. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report