赣州建网站,如何自学做网站,网站策划建设方案书,做网站为什么要租服务器int pause(void); 作用#xff1a;使调用进程#xff08;线程#xff09;进入休眠状态#xff08;就是挂起#xff09;#xff1b;直到接收到信号且信号函数成功返回 pause函数才会返回 返回值#xff1a;始终返回-1 示例代码:
#include sys/types.h…int pause(void); 作用使调用进程线程进入休眠状态就是挂起直到接收到信号且信号函数成功返回 pause函数才会返回 返回值始终返回-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
// 实验说明: 执行程序的过程中按CTL C不能是程序退出, 而是执行我们安装的信号处理函数void sig_ctlc(int sig) // sig参数是信号,如 SIGINT,其值为2
{printf(sig %d: sig_ctlc func\n, sig);getchar();printf(sig_ctlc return\n);
}
int main(int argc, char **argv)
{// 安装信号 if(SIG_ERR signal(SIGINT, sig_ctlc))perror(SIGINT install err\n);// signal(SIGINT, SIG_IGN); // 忽略SIGINT信号// signal(SIGINT, SIG_DFL); // 对于SIGINT信号,使用默认处理函数printf(pause before\n);// 1.当我们没有发送信号时pause会阻塞// 2.当进程接收到到信号时不会立刻返回, 只有当信号处理函数返回时, pause才会返回-1.pause();printf(pause after\n);return 0;
}
/* 执行效果:bookgui_hua_shu:/work/nfs_root/qt_fs_new/2system_pro/sig$ ./a.outpause before^Csig 2: sig_ctlc func // 发送了ctl c 信号 sig SIGINT 2c // 输入c\nsig_ctlc returnpause after
*/