新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

[Linux信号]使用sigqueue函数发送信号

/*
使用sigqueue函数向进程自身发送一个SIGUSR1信号,
并获取该信号的信号值
*/
#include
#include
#include
//SIGUSR1的处理函数
void signalDeal(int signo,siginfo_t *info,void *context)
{
    char *pMsg=(char*)info->si_value.sival_ptr;
    printf("接收到的信号标号是:%d\n", signo);
    printf("接收到信息:%s\n", pMsg);
}
//主函数
int main(int argc,char *argv[])
{
    struct sigaction sigAct;
    sigAct.sa_flags = SA_SIGINFO;
    sigAct.sa_sigaction = signalDeal;
    if(sigaction(SIGUSR1,&sigAct,NULL)==-1)
    {
        printf("sigaction函数调用失败!\n");
        exit(1);
    }
    sigval_t val;
    char pMsg[ ]="this is a test!";   //这是一段测试用的字符串
    val.sival_ptr = pMsg;
    if(sigqueue(getpid(),SIGUSR1,val) == -1)
    {
        printf("sigqueue函数调用失败!\n");
        exit(1);
    }
    sleep(3);     //休眠3秒
    return 0;
}

分享题目:[Linux信号]使用sigqueue函数发送信号
本文网址:http://www.wjwzjz.com/article/gcidhj.html
在线咨询
服务热线
服务热线:028-86922220
TOP