我需要fork两个子进程。 一个可以接收信号3,打印hello并将信号4发送到另一个子进程; 另一个可以接收信号4,打印world并将信号3发送到第一个子进程。
首先,父进程将在睡眠3秒钟后将信号3发送到第一个子进程。
然后3秒后,父进程将发送SIGKILL杀死他们两个。
我不知道如何向特定的子进程发送信号(我知道我们有一个函数kill来发送信号,但是我不知道在这里使用它)。
这是我的代码:
#include
#include
#include
#include
#include
void func(int n)
{
printf("ping
");
// how to send signal 4 to the second process?
}
void func2(int n)
{
printf("pong
");
// how to send signal 3 to the first process?
}
int main()
{
pid_t pid;
int i;
for(i = 0; i < 2; i++)
{
pid = fork();
if(pid == 0)
{
if(i == 0)
{
sign