objects and fork command?

Discussion in 'Perl' started by Doug Nichols, Aug 6, 2004.

  1. Doug Nichols

    Doug Nichols Guest

    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});
    }
    }
    Doug Nichols, Aug 6, 2004
    #1
    1. Advertising

  2. Doug Nichols

    Guest

    (Doug Nichols) wrote in message news:<>...
    > 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).
    , Aug 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lingyun Yang
    Replies:
    4
    Views:
    11,787
    Keith Dart
    Dec 16, 2004
  2. 7stud
    Replies:
    11
    Views:
    670
    Dennis Lee Bieber
    Mar 20, 2007
  3. Eric Snow

    os.fork and pty.fork

    Eric Snow, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    560
    Eric Snow
    Jan 8, 2009
  4. rajendra

    fork command.

    rajendra, Jul 26, 2007, in forum: Perl Misc
    Replies:
    12
    Views:
    154
    Ted Zlatanov
    Jul 31, 2007
  5. Jacob JKW
    Replies:
    12
    Views:
    186
    Jacob JKW
    Jun 20, 2008
Loading...

Share This Page