问题是通过SIGUSR1和SIGUSR2实现父子进程的交替数数
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <signal.h>
#include <sys/time.h>
#include <pthread.h>
#include <semaphore.h>
int num=1;
int flag;
void father(int signo)
{
    printf("father process:num[%d]\n",num);
    num+=2;;
    flag=0;
    sleep(1);
}
void son(int signo)
{
    printf("child process:num[%d]\n",num);
    num+=2;
    flag=0;
    sleep(1);}
void sigint(int signo)
{}
int main(int argc,char *argv[])
{
    int pid;
    if((pid=fork())<0)
    {
        perror("fork");
        return -1;
    }
    if(pid>0)
    {
        num=0;
        flag=1;
        struct sigaction act;
        act.sa_flags=0;
        act.sa_handler=father;
        sigaddset(&act.sa_mask,SIGUSR1);//已经设置阻塞信号集了,当SIGUSR1被触发的时候,会被阻塞,可运行为什么不会阻塞。
        //sigprocmask(SIG_BLOCK,&act.sa_mask,NULL);//加上这句话就会阻塞,为什么?
        sigaction(SIGUSR1,&act,NULL);
        //signal(SIGUSR1,father);
        //signal(SIGINT,sigint);
        while(1)
        {
            if(flag==0)
            {
                kill(pid,SIGUSR2);
                flag=1;
            }
        }
    }
    if(pid==0)
    {
        num=1;
        flag=0;
        struct sigaction act;
        act.sa_flags=0;
        act.sa_handler=son;
        sigaddset(&act.sa_mask,SIGUSR2);
        //sigprocmask(SIG_BLOCK,&act.sa_mask,NULL);
        sigaction(SIGUSR2,&act,NULL);
        //signal(SIGUSR2,son);
        //signal(SIGINT,sigint);
        while(1)
        {
            if(flag==0)
            {
                kill(getppid(),SIGUSR1);
                flag=1;
            }
        }
    }
    return 0;
}