Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand SIGALRM signal

Shulou Source: shulou.com Published: 2022-06-01 16:06:55 09月19日 Update

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)

Tags: Signal process system function information timing clock content article time time more knowledge article processing scheduling yes operating system superscript function Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Redmi Microsoft Shulou Information