in reply to using system and exec in same script using child

The if is executed in both the parent and the child, as made obvious by the "then" part being executed in the parent and the "else" part being executed in the child.

So why do you think the line that follows the if would only be executed in the parent?

exec replaces the program the process is executing with another and it never returns (except on error). So yes, using exec is appropriate since you don't want to continue executing the program int he child.

By the way, system is a combination of fork, exec and wait or waitpid. That might fail if the child launched by fork ends before the child launched by system. You might have to avoid using system to customize the use of wait

Replies are listed 'Best First'.
Re^2: using system and exec in same script using child
by cdarke (Prior) on Jan 11, 2010 at 10:59 UTC
    To add to ikegami's reply, the parent could exit before the child gets a look-in, and that would (probably) send a SIGHUP to the child and kill it. You should consider a wait or waitpid in the parent before it exits (or maybe IGNORE SIGHUP).
      so, can regular perl program have multiple sub working at sametime? Like displaying moving dots while calculating or simulatenaously launching two external program from perl script.. is that not possible? What I thought of child process is wrong as it's running the same program I am running twice.. i need ways(or at least clue) on how to do above things without running full program of it's own.
        can regular perl program have multiple sub working at sametime?

        Sure can:

        use threads; async{ print "I'm doing this over here while he's...", sleep 1 while 1 }; print "doing that over there, while...", sleep 1 while 1; I'm doing this over here while he's... 1.001 doing that over there, while... 1.001 I'm doing this over here while he's... 0.999772 doing that over there, while... 0.999429 I'm doing this over here while he's... 0.999626 doing that over there, while... 0.99956 I'm doing this over here while he's... 0.999724 doing that over there, while... 0.999355 Terminating on signal SIGINT(2)

        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.

        so, can regular perl program have multiple sub working at sametime?

        Yes, if threads are used.