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

歡迎訪問 生活随笔!

生活随笔

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

linux

Linux pause函数 详解

發(fā)布時(shí)間:2023/11/30 linux 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Linux pause函数 详解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

int pause(void);
  作用:使調(diào)用進(jìn)程(線程)進(jìn)入休眠狀態(tài)(就是掛起);直到接收到信號(hào)且信號(hào)函數(shù)成功返回 pause函數(shù)才會(huì)返回
  返回值:始終返回-1
 示例代碼:

#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <strings.h> #include <string.h> #include <sys/types.h> #include <errno.h> #include <signal.h> // 實(shí)驗(yàn)說明: 執(zhí)行程序的過程中按CTL + C不能是程序退出, 而是執(zhí)行我們安裝的信號(hào)處理函數(shù)void sig_ctlc(int sig) // sig參數(shù)是信號(hào),如 SIGINT,其值為2 {printf("sig = %d: sig_ctlc func\n", sig);getchar();printf("sig_ctlc return\n"); } int main(int argc, char **argv) {// 安裝信號(hào) if(SIG_ERR == signal(SIGINT, sig_ctlc))perror("SIGINT install err\n");// signal(SIGINT, SIG_IGN); // 忽略SIGINT信號(hào)// signal(SIGINT, SIG_DFL); // 對(duì)于SIGINT信號(hào),使用默認(rèn)處理函數(shù)printf("pause before\n");// 1.當(dāng)我們沒有發(fā)送信號(hào)時(shí)pause會(huì)阻塞// 2.當(dāng)進(jìn)程接收到到信號(hào)時(shí)不會(huì)立刻返回, 只有當(dāng)信號(hào)處理函數(shù)返回時(shí), pause才會(huì)返回-1.pause();printf("pause after\n");return 0; } /* 執(zhí)行效果:book@gui_hua_shu:/work/nfs_root/qt_fs_new/2system_pro/sig$ ./a.outpause before^Csig = 2: sig_ctlc func // 發(fā)送了ctl +c 信號(hào) sig = SIGINT = 2c // 輸入c\nsig_ctlc returnpause after */

?

總結(jié)

以上是生活随笔為你收集整理的Linux pause函数 详解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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