in reply to Executing a process in the background AND getting its pid

One of the following "forking opens" might suit your needs

my $pid = open my $fhOut, "| the command ", or die ...; ## or my $pid = open my $fhIn, "the command |", or die ...; ## or using the 3-arg form on *nix systems my $pid = open my $fhOut, '|-', "the command ", or die ...; ## or my $pid = open my $fhIn, '-|', "the command", or die ...;

Or list forms of the latter two, if you need to pass arguments, may make sense on your system.

See open and perlopentut for more information.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Executing a process in the background AND getting its pid
by henrikbe (Novice) on Jun 12, 2007 at 08:05 UTC
    Thank you, this seems to work fine!

    Henrik

Re^2: Executing a process in the background AND getting its pid
by Anonymous Monk on Jun 12, 2012 at 17:54 UTC
    Thanks for your help. I am having problem getting actual PID of process. Your open command returns the PID which is less than 1 of actual PID. for ex. PID of my actual process is 1923, i get 1922 which i discovered to be a zombie process. Can you please tell me what should i do to get the actual process id ? thanks in advance.

      Can you post the (exact) code you are using please.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?