objects and fork command?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Doug Nichols

    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}) ;
    }
    }
  • nobull@mail.com

    #2
    Re: objects and fork command?

    doug_x_nichols@ yahoo.com (Doug Nichols) wrote in message news:<78443f00. 0408061455.1eba 882d@posting.go ogle.com>...[color=blue]
    > 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}) ;
    > }
    > }[/color]

    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).

    Comment

    Working...