Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Under solaris with a non-threads version of Perl 5.6.1, I am watching my process with ptree. I hope someone may be able to explain the behavior. The program uses backticks and makes several calls to system, but I frequently see my script's name repeated twice on the ptree, even though it doesn't call itself. Is this a side effect of fork?

6852 perl -w script.pl 9768 perl -w script.pl ? Doesn't call self ?

Despite the fact the script doesn't invoke itself, the ptree shows it being a child of itself. If this fork or system? Some other magic?

Replies are listed 'Best First'.
Re: Spawning self - are backticks forking with same name
by Joost (Canon) on Aug 31, 2007 at 22:06 UTC
Re: Spawning self - are backticks forking with same name
by perlofwisdom (Pilgrim) on Aug 31, 2007 at 21:32 UTC
    When your perl script makes an external call (via system(), or backticks ``, and other methods) a sub-process is kicked off on the operating system. This sub-process is tied to your original script (parent/child). When the process completes, the child process goes away. So, you were on the right track all along.
Re: Spawning self - are backticks forking with same name
by bruceb3 (Pilgrim) on Aug 31, 2007 at 21:38 UTC
    Using Solaris 10 and a trival Perl script, I can not reproduce the same symptoms. Here is the script;
    sleep 120;
    Then to get it started I am running it using the perl command.
    # perl -w p.pl
    The output of ptree is doesn't have two perl processes like you are seeing.
    624 /sbin/sh 625 bash --login -o vi 651 perl -w p.pl
    I realise that we are using different versions of Solaris (you are most likely running Solaris 9) but I don't thin that this would make a difference.

    What is happening in your script? Are you using open with a "|" somewhere?