信号

//信号
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>

void handler(int signal_num)
{
        switch(signal_num)
        {
                case SIGINT:
                {
                        printf("Ctrl +C\n");
                }
        }
}


int main(int argc,char *argv[])
{
        signal(SIGINT,handler);
        while(1)
        {
                printf("hello world\n");
                sleep(1);
        }
        /*pid_t child;
        child = fork();
        if(child == 0)
        {
                printf("Parrent [%d] create child [%d] \n",getppid(),getpid());
                exit(0);
        }
        else if(child > 0)
        {
                printf("Parrent [%d] create success!\n",getpid());
        }
        printf("Parrent [%d] quit!\n",getpid());*/
        return 0;
}

你可能感兴趣的:(信号)