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

How to understand SIGALRM signal

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

Share

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

This article will explain in detail how to understand SIGALRM signals, the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

SIGALRM signal is one of the signals in the operating system. Its function is to set how often the process will receive a SIGALRM signal. Let's take a look at his implementation principle.

The alarm system call is a function that sets how long the SIGALRM signal is triggered. Here is his statement.

# include

Unsigned alarm (unsigned seconds)

Let's see how it works.

Int sys_alarm (long seconds)

{

Int old = current- > alarm

/ / calculate the original time

If (old)

Old = (old-jiffies) / HZ

/ *

The system triggers a clock interrupt every n seconds. Jiffies is the number of clock interruptions that have occurred in the system.

1 second is equal to HZ jiffies. Here, the number of jiffies is calculated, that is, how many times the clock interrupt occurs and then the SIGALRM signal is triggered.

, /

Current- > alarm = (seconds > 0)? (jiffies+HZ*seconds): 0

/ / return to the old

Return (old)

}

We see that the alarm field in PCB records the time when the SIGALRM signal was triggered. Let's take another look at the timing of the trigger.

, /

Void schedule (void)

{

Int i,next,c

Struct task_struct * * p

/ / traversing the process

For (p = & LAST_TASK; p > & FIRST_TASK;-- p)

If (* p) {

/ *

Determine if alarm is set and expired

Alarm

< jiffies说明过期了。设置alarm信号,清除设置标记 */ if ((*p)->

Alarm & & (* p)-> alarm

< jiffies) { (*p)->

Signal | = (1)

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