![]() |
objects and fork command?
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}); } } |
Re: objects and fork command?
doug_x_nichols@yahoo.com (Doug Nichols) wrote in message news:<78443f00.0408061455.1eba882d@posting.google. com>...
> 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). |
| All times are GMT. The time now is 03:10 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.