利用在C信号间同步,LINUX [英] Interprocess synchronization using signals in c, linux

查看:78
本文介绍了利用在C信号间同步,LINUX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

工艺甲叉说4子进程。执行exec()是用来取代儿童的code。孩子初始化并等待家长来创建所有的4。

Process A forks say 4 child processes. exec() is used to replace the code of the children. The children initialize and have to wait for the parent to create all of the 4 of them.

然后上级发送一个SIGUSR1到每个子进程,以便他们开始处理。父等待所有孩子完成处理。第。当孩子完成其工作,它发送一个SIGUSR2父。当父接收所有SIGUSR2信号,它可以继续执行,合并子进程的计算。

Then the parent sends a sigusr1 to each child process in order for them to start processing. The parent waits for all the children to complete procesing. When a child finishes its work it sends a sigusr2 to the parent. When the parent receives all the sigusr2 signals it continues with execution, merging the calculations of the child processes.

这是一所大学的运动,并在这一过程中(父)类据称会失去一些信号,所以我们被告知只要求孩子信号的百分比被成功接收。

This is a university exercise, and it was stated in class that process A (parent) will lose some signals, so we were told to only require a percentage of the children signals to be received successfully.

我要达到100%。在其他情况下是一个暂停()和环去工作?

I would like to achieve 100%. In the other case is a pause() and a loop going to work?

推荐答案

如果您使用标准信号()方法,过程中的一个可以失去,如果许多孩子一些信号送他相同的信号在很短的时间。如果你在这段时间内的同一个处理的信号和接收,你将失去第二(更多precisely它会被默认信号处理程序被逮住)。

If you use the standard signal() method, the process A can lose some signals if many children send him the same signal in a very short time. If you're handling a signal and receive during this time the same one, you will lose the second (more precisely it will be catched by the default signal handler).

如果您决定使用 的sigaction() 你就可以捕获所有发送到你的进程的信号。

If you decide to use sigaction() you'll be able to catch all the signals sent to your process.

这篇关于利用在C信号间同步,LINUX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆