这个程序会创建一个子进程,子进程会等待一个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’