#!/usr/bin/perl use strict; use warnings; use Time::HiRes 'usleep'; my $num_processes = 10; my $signals_per_process = 1000; $| = 1; my @pids; $SIG{USR2} = sub { print "parent received ".Time::HiRes::time().$/ }; FORKS: while ($num_processes > 0) { my $parent = $$; if (my $pid = fork()) { push @pids, $pid; } else { $SIG{USR1} = sub { print $$." received ".Time::HiRes::time().$/; }; while (1) { usleep(rand(20)); print "parent signalled ".Time::HiRes::time().$/; kill('USR2',$parent) or exit; } exit; } $num_processes--; } for (1..$signals_per_process) { PROCESS: foreach my $id (@pids) { print $id." signalled ".Time::HiRes::time().$/; kill("USR1", $id); usleep(rand(20)); } } exit; #### #!/usr/bin/perl use warnings; use strict; my %data; my %report; while () { chomp; my ($pid, $op, $time) = split /\s/; if ($op eq 'signalled') { push @{$data{$pid}}, $time; } else { my $sigtime = pop @{$data{$pid}}; push @{$report{$pid}}, $time - $sigtime; } } print "Summary".$/; print "Lost:".$/; foreach my $pid (sort keys %data) { print $pid.": ".scalar(@{$data{$pid}}).$/; } print "Received: ".$/; foreach my $pid (sort keys %report) { my ($min, $max, $count, $sum); foreach my $time (@{$report{$pid}}) { $min = $time if (not defined $min or $min > $time); $max = $time if (not defined $max or $max < $time); $count++; $sum += $time; } print $pid.": $max, $min, $count, ".$sum/$count.$/; }