在执行信号处理程序来一个信号会如何样

在执行信号处理程序来一个信号会怎么样?
如果来的是同一个信号呢?
我知道在可靠信号处理机制下信号会被阻塞,那在不可靠信号机制下呢?是丢弃还是再次中断?

如果来的是不同的信号呢?


owenliang@linux-7lsl:~/csdn/src> ./main &
[2] 14084
owenliang@linux-7lsl:~/csdn/src> kill -SIGINT 14084
owenliang@linux-7lsl:~/csdn/src> !kill -SIGINT 14084
owenliang@linux-7lsl:~/csdn/src> !kill -SIGINT 14084
owenliang@linux-7lsl:~/csdn/src> kill -SIGINT 14084
owenliang@linux-7lsl:~/csdn/src> kill -SIGINT 14084
owenliang@linux-7lsl:~/csdn/src> !
owenliang@linux-7lsl:~/csdn/src> 

充分展示了信号不排队, 信号屏蔽, 一个线程一个掩码的事实.

C/C++ code

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
/*
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
*/

void* thread_func(void*)
{
while(1)
{
pause();
}
}

void sigfunc(int)
{
write(1, "!", 1);
sleep(10);
}

int main()
{
pthread_t tid;

signal(SIGINT, sigfunc);

if (pthread_create(&tid, NULL, thread_func, NULL) == -1)
{
perror("pthread_create");
exit(1);
}

while(1)
{
pause();
}

return 0;
}

在执行信号处理程序来一个信号会如何样

相关文章:

你感兴趣的文章:

标签云: