我有这个由9个进程组成的多进程程序。一个是产生3个信号产生过程和4个信号处理过程的主要过程。一个是监测过程。现在我已经使用了两个信号SIGUSR1和SIGUSR2。每个处理程序都可以处理SIGUSR1或SIGUSR2。每当它们收到一个信号时,它们将共享存储器中SIGUSR1和SIGUSR2信号的计数增加1.由于信号被发送到进程组,所以监视进程也接收到这些信号。它可以处理这两个信号,并将其本地信号计数增加1.每当它达到10时,它就会在共享内存中输出SIGUSR1和SIGUSR2的计数值。多进程信号处理程序中的奇怪结果
我在主程序中有这个选项,它可以运行30秒并终止程序,在这种情况下,我会睡眠(30),然后终止程序。在第二种情况下,它忙于在while循环中等待,计算共享内存中SIGUSR1和SIGUSR2的总数。当它达到100000时,它终止程序。
这里是我的两个版本
对于100000第二版本
对于100000信号版本输出
Initializing the shared memory
End of initializing the shared memory
Registering the signal handlers
End of registering the signal handlers
Registering the monitoring process
Monitor's pid is 6635
End of registering the monitoring process
Registering the signal generators
Interval SIGUSR1 = 5.79953e-05
Interval SIGUSR2 = 8.69632e-05
Count SIGUSR1 = 10
Count SIGUSR2 = 10
Count SSIGUSR1 = 5
Count SSIGUSR2 = 5
Interval SIGUSR1 = 7.64132e-05
Interval SIGUSR2 = 5.72999e-05
Count SIGUSR1 = 16
Count SIGUSR2 = 24
Count SSIGUSR1 = 8
Count SSIGUSR2 = 12
对于30秒的版本
初始化共享输出内存
End of initializing the shared memory
Registering the signal handlers
End of registering the signal handlers
Registering the monitoring process
Monitor's pid is 6719
End of registering the monitoring process
Registering the signal generators
Inside option 1
Interval SIGUSR1 = 0.000246763
Interval SIGUSR2 = 0.000222743
Count SIGUSR1 = 93
Count SIGUSR2 = 222
Count SSIGUSR1 = 92
Count SSIGUSR2 = 111
Interval SIGUSR1 = 0.000664711
Interval SIGUSR2 = 0.000390577
Count SIGUSR1 = 102
Count SIGUSR2 = 234
Count SSIGUSR1 = 97
Count SSIGUSR2 = 117
为什么结果如此滞后于第二种情况。我的意思是当显示器首次打印输出时,由处理线程记录的SIGUSR1和SIGUSR2的计数已经达到了93和222.此外,信号被发送到进程组。所以每个信号都由两个处理器和一个监视器处理。在处理程序中只有两个,因为四个hander中有两个处理SIGUSR1,忽略另一个信号,反之亦然。
所以你可以看到什么错误,当我睡觉(30),看到结果。任何见解。我一直试图调试这几天但尚未成功。