-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathforktest
executable file
·50 lines (40 loc) · 945 Bytes
/
forktest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/perl -w
use strict;
use Log::Log4perl qw(:easy);
# Log::Log4perl->easy_init({ level => $DEBUG, layout => "%F{1}:%L %m%n"});
use Data::Throttler;
my $db_file = "db_file.dat";
unlink $db_file;
my $throttler = Data::Throttler->new(
interval => 120,
max_items => 1000,
backend => 'YAML',
backend_options => {
db_file => $db_file,
}
);
my $pid = fork();
if( !defined $pid ) {
die "fork failed: $!";
}
if( $pid ) {
# parent
push_test( $throttler );
DEBUG "Parent done";
waitpid( $pid, 0 );
} else {
# child
push_test( $throttler );
DEBUG "Child done";
exit 0;
}
###########################################
sub push_test {
###########################################
my( $throttler ) = @_;
for( 1... 100 ) {
$throttler->try_push(key => "foobar");
$throttler->try_push(key => "foobar");
$throttler->try_push(key => "foobar");
}
}