日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > linux >内容正文

linux

linux下如何屏蔽代码,linux c 怎么屏蔽信号 使用sigprocmask命令

發(fā)布時(shí)間:2025/3/19 linux 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux下如何屏蔽代码,linux c 怎么屏蔽信号 使用sigprocmask命令 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

SIGPROCMASK(2)???????????? Linux Programmer's Manual??????????? SIGPROCMASK(2)

NAME

sigprocmask - examine and change blocked signals

功能? sigprocmask - 測(cè)試和改變被屏蔽的信:號(hào)

?SYNOPSIS

頭文件??? #include

?函數(shù)????? int sigprocmask(int how, const sigset_t *set, sigset_t *oldset);

參數(shù):

?how:

??????? The behavior of the call is dependent on the value of how, as follows.

SIG_BLOCK

The set of blocked signals is the union of the current? set? and

the set argument.

SIG_UNBLOCK

The? signals? in set are removed from the current set of blocked

signals.? It is permissible to attempt to unblock a signal which

is not blocked.

SIG_SETMASK

The set of blocked signals is set to the argument set.

?*set:

??????? If set is NULL, then? the? signal? mask? is? unchanged? (i.e.,? how? is

ignored),? but? the? current? value? of the signal mask is nevertheless

returned in oldset (if it is not NULL).

?*oldset:

?

If? oldset is non-NULL, the previous value of the signal mask is stored

in oldset.

?返回值:成功返回0,失敗返回-1

?

?? 1 //屏蔽2號(hào)信號(hào)

2 #include

3 #include

4

5 int main(void){

6???? sigset_t set,oset;

7???? //將集合清空

8???? sigemptyset(&set);

9???? //將2信號(hào)添加到集合set里

10???? sigaddset(&set,SIGINT);

11???? sigprocmask(SIG_SETMASK,&set,&oset);

12 //??? sigprocmask(SIG_BLOCK,&set,&oset);

13???? while(1);

14???? return 0;

15 }

?前臺(tái)與后臺(tái)之間轉(zhuǎn)換過(guò)程

1)在shell下,啟動(dòng)一個(gè)前臺(tái)進(jìn)程。

2)用戶按下crtl+c,這個(gè)鍵盤(pán)輸入產(chǎn)生一個(gè)硬件中斷

3)如果此時(shí)cpu正在運(yùn)行進(jìn)程的用戶空間代碼,

需要切換到內(nèi)核空間,處理硬件中斷。

4)中斷驅(qū)動(dòng)程序?qū)rtl+c 解釋成一個(gè)sigint信號(hào),記

在該進(jìn)程的PCB中。

5)從內(nèi)核返回到用戶空間的時(shí)候,先檢查

進(jìn)程的PCB中是否有信號(hào)到達(dá)。如果有信號(hào)到達(dá),

調(diào)用信號(hào)處理函數(shù)。

6)處理完畢后,繼續(xù)返回內(nèi)核,再次判斷是否有信號(hào)到達(dá)。

如有切換到第五步,沒(méi)有,返回進(jìn)程的用戶態(tài),繼續(xù)執(zhí)行。

?

總結(jié)

以上是生活随笔為你收集整理的linux下如何屏蔽代码,linux c 怎么屏蔽信号 使用sigprocmask命令的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。