objects and fork command?

D

Doug Nichols

I have an object that is created that does a fork. The parent needs to
remove the lock file it created when it is complete, but the child
processes will not really have any files to remove.

The problem is the parent doesn't seem to delete the files- like the
DESTROY never happens. when the parent end.

What gives??

Thanks in advance.
dn


--- file testa
sub new {
my $self = shift;
$self = { LOCK_FILE => 'this.pid', };
bless $self;
if (my $pid = fork()) { parent stuff....
finihs end exit!
} elsif (defined($pid)) { child stuff....
go do something for while....
exit 0;
} els........
return $self;
}


sub DESTROY {
my $self = shift;
my $pid = $1 if (`cat $self->{LOCK_FILE}` =~ /\D*(\d+)\D*/);
if ($$ == $pid) {
unlink ($self->{LOCK_FILE});
}
}
 
N

nobull

I have an object that is created that does a fork. The parent needs to
remove the lock file it created when it is complete, but the child
processes will not really have any files to remove.

The problem is the parent doesn't seem to delete the files- like the
DESTROY never happens. when the parent end.

What gives??

Thanks in advance.
dn


--- file testa
sub new {
my $self = shift;
$self = { LOCK_FILE => 'this.pid', };
bless $self;
if (my $pid = fork()) { parent stuff....
finihs end exit!
} elsif (defined($pid)) { child stuff....
go do something for while....
exit 0;
} els........
return $self;
}


sub DESTROY {
my $self = shift;
my $pid = $1 if (`cat $self->{LOCK_FILE}` =~ /\D*(\d+)\D*/);
if ($$ == $pid) {
unlink ($self->{LOCK_FILE});
}
}

What you appear to be doing looks like it should work. But you have
not posted real code.

Please post a minimal but complete script that you have actually run
and found to display the symptoms you describe.

This (and lots more) helpful advice can be found in the posting
guidelines that are regularly posted to the newsgroup that superceded
this one when this newsgroup ceased to exist many years ago (see FAQ).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top