- 论坛徽章:
- 0
|
#include
#include
#include
void new_op(int,siginfo_t*,void*);
int main(int argc,char**argv)
{
struct sigaction act;
int sig;
pid_t pid;
pid=getpid();
sig=atoi(argv[1]);
sigemptyset(&act.sa_mask);
act.sa_sigaction=new_op;
act.sa_flags=SA_SIGINFO;
if(sigaction(sig,&act,NULL)si_int);
}
输出:
child pid is 21309
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
wait for the signal
pid is 21309 the int value is 66
pid is 21309 the int value is 66
信号处理函数中打印的进程号和子进程是一致的,子进程继承了父进程对信号的处理。
再来看看fork系统调用的说明:
功能描述:
建立一个子进程。所建立的子进程PID 和 PPID不同于其父进程,同时资源使用被设置为0,文件锁和挂起的信号不被继承。
Linux内部,fork的执行使用copy-on-write页面,所以耗费的资源只是拷贝父进程页表,建立唯一子进程task结构体的时间和内存。
其中提到了挂起的信号不被继承,哪什么是挂起的信号呢?[color="#000000"]已经生成但还未被传递的信号被称为挂起的信号。
在进程的task_struct结构中有关于本进程中未处理信号的数据成员:
struct sigpending pending:
struct sigpending{
struct sigqueue *head, **tail;
sigset_t signal;
};
其中head和tail是信号队列的指针,挂起的信号就是已经添加到信号队列里,但还没有处理的信号。
[color="#000000"]参考资料[color="#000000"]http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html
[color="#000000"]http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72751/showart_1133793.html |
|