Hi,
I'm trying to write a daemon that accesses my database. I thought I could
create the connection in the parent, and use it in the child. But that
doesn't seem to work. Below is the code. Any help would be appreciated
Thanks
Jay
#!/usr/bin/perl -w
use strict;
use DBI;
use POSIX qw(setsid);
$|=1;
my $service = "o817";
my $userid = "jstrauss";
my $passwd = "passwd";
my $dbh = DBI->connect("dbi:Oracle:$service","$userid","$passwd",
{ RaiseError => 1, AutoCommit => 0 }) or
die "Can't connect to Oracle database: $DBI::errstr\n";
my $sth = $dbh->prepare("select fromuser, touser from refresh");
&daemonize;
while(1) {
print "Hello...\n";
$sth->execute;
while (my @row = $sth->fetchrow_array ) {
print "$row[0] - $row[1]\n";
}
sleep(5);
}
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
umask 0;
}