错误编译过程SIGALRM kill

时间:2012-04-23 01:19:35

标签: c linux fork alarm

这个程序会创建一个子进程,子进程会等待一个ALARM信号,当这个信号在3秒后到达时,f函数将获取父进程ID,并发送一个SIGINT信号来杀死它,所以孩子将在3秒后杀死父母

#include <stdio.h>
    #include <unistd.h>
    #include <signal.h>
    #include <string.h>

    void f(int sig)
    {
        kill(getppid(),SIGINT);
    }

    main()
    {
        int f=fork();
        if(f==0)
        {
            signal(SIGALRM,f);
            alarm(3);
        }
        else
        {
            pause();
        }
    }

我收到了这个错误:

test13.c: In function ‘main’:
test13.c:16:3: warning: passing argument 2 of ‘signal’ makes pointer from integer without a cast
/usr/include/signal.h:101:23: note: expected ‘__sighandler_t’ but argument is of type ‘int’

2 个答案:

答案 0 :(得分:6)

停止使用您的变量踩踏f

答案 1 :(得分:2)