快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

[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://6mz.cn/article/gcidhj.html

其他资讯