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

What different between below system() function call.
First one wait until specified sleep values . But second one does not .
Note :
+ I have to run child as background process
+ Parent process should not wait for the child process completion.
code of bar.pl file :
use strict; use warnings; print "Before background process start \n"; system("foo.pl","&"); #system("foo.pl & "); print "After background process start ";
code of foo.pl file :
use strict; use warnings; sleep(100);

Replies are listed 'Best First'.
Re: system function behaviour
by lakshmananindia (Chaplain) on Apr 04, 2009 at 06:35 UTC
    system("foo.pl","&");#& will pass as an argument to foo.pl #Try printing the @ARGV in foo.pl.
    system("foo.pl &"); #Process runs in the background.
    --Lakshmanan G.

    The great pleasure in my life is doing what people say you cannot do.


Re: system function behaviour
by shmem (Chancellor) on Apr 04, 2009 at 12:33 UTC
    system("foo.pl","&");

    This calls foo.pl with the character & as its first argument.

    system("foo.pl & ");

    This calls /bin/sh (or your appropriate system shell) and passes it the whole string as command. The shell then interprets the & as a directive to background the command.

    The next two are equivalent, but only in the second the shell is involved:

    system("foo.pl", "&"); system("foo.pl '&' ");
Re: system function behaviour
by nagalenoj (Friar) on Apr 04, 2009 at 06:38 UTC
    Dear monk,

    Hope this will help you system.