代码:
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
typedef void (*sighander_t)(int);
void hander1(int sig)
{
printf("sig = %d\n",sig);
while(1)
{
printf("3号在运行\n");
sleep(1);
}
return;
}
void hander2(int sig)
{
printf("sig = %d\n",sig);
return;
}
int main(int argc, const char *argv[])
{
sighander_t s = signal(3,hander1);
if(SIG_ERR == s)
{
perror("signal");
return -1;
}
printf("s = %p __%d__",s,__LINE__);
s = signal(20,hander2);
if(SIG_ERR == s)
{
perror("signal");
return -1;
}
printf("s = %p __%d__",s,__LINE__);
while(1)
{
printf("main\n");
sleep(1);
}
return 0;
}
现象: