use warnings; use strict; use Parallel::ForkManager; use DBI; my $db_file = 'test.db'; my $dbh = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "", {RaiseError => 1} ) or die $DBI::errstr; my $pm = Parallel::ForkManager->new(20); for (1..2){ $pm->start and next; my $interval = $_ / 5; my $dbh = DBI->connect( "dbi:SQLite:dbname=$db_file", "", "", {RaiseError => 1} ) or die $DBI::errstr; while (1){ dbwrite($dbh, $interval); #sleep 1; } } while(1){ my $sth = $dbh->prepare( "SELECT * FROM test WHERE id=?;" ); $sth->execute('test'); my $val = $sth->fetchrow_hashref()->{value}; print "$val\n"; } sub dbwrite { my ($dbh, $interval) = @_; my $sth = $dbh->prepare( 'UPDATE test SET value=? WHERE id="test";' ); $sth->execute($interval); };