Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: Perl + forking

  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Perl + forking

    I have a perl script that forks a command from the parent process and then kills it a few seconds later. The problem I am running into is that sometimes the process isn't killed(the script tries to kill the wrong pid). For whatever reason I am having to increment the pid of my spawned process by +1 to get the correct number. Please see the code below...

    Code:
      $SIG{CHLD} = 'IGNORE';
      my $pid = fork();
      if (not defined $pid) {
          warn "resources not available.\n";
      }
      elsif ($pid == 0) {
          exec($cmd);
          exit(0);
      }
      else {
          sleep(2);
          $pid++;
          kill 9, $pid;   
      }
    Any help is much appreciated!

  • #2
    Master Coder
    Join Date
    Apr 2003
    Location
    in my house
    Posts
    5,211
    Thanks
    39
    Thanked 201 Times in 197 Posts
    if that fork(); is a function can we see it? maybe the value of pid is being created differently from how you think?

    bazz
    "The day you stop learning is the day you become obsolete"! - my late Dad.

    Why do some people say "I don't know for sure"? If they don't know for sure then, they don't know!
    Useful MySQL resource
    Useful MySQL link


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •