in reply to How to reduce memory by killing redundant perl executables

using exec instead of system will transfer control to the second script. This means that only one script will be running at any given time.
  • Comment on Re: How to reduce memory by killing redundant perl executables

Replies are listed 'Best First'.
Re: Re: How to reduce memory by killing redundant perl executables
by MZSanford (Curate) on Jul 13, 2001 at 17:27 UTC
    Per a request from the Chatterbox, it can never hust to have a brush up on the diffrences between system() and exec(). While the internal implimentation depends on the operating system, here are the genral diffrences :

    system(): The system($command) command does the same thing as typing a command at the prompt in unix. A new child process is created, the program itself is loaded (be it /bin/ls or /usr/bin/perl), and begins processing (i will ignore the calls at a level lower than that).

    exec(): The exec($command) call is quicker, because rather than creating a child process, and then loading the program to be run, it instead loads the program to be run into the current memory space. This means that if a.pl, running under pid 3 does exec("ls"), then the perl program will be unloaded from memory and the machine code for ls will be loaded in it's place, and will begin running under pid 3.

    So, in short, system() creates a new process, in fresh memory.while exec() replaces the current program with the new one. An interesting note is that when using exec, the stdin, stderr and stdout are passed to (rather, inherited by) the new process, so reopening them will effect the next program.
    OH, a sarcasm detector, that’s really useful
Re: Re: How to reduce memory by killing redundant perl executables
by juo (Curate) on Jul 13, 2001 at 16:39 UTC

    The perl scripts are launched from within another application that supports Perl scripting so the moment I start using exec the interaction with that application is lost also. I only want to kill the Perl script.

      Now, I'm thoroughly confused as to your setup and what you want to do with it. What exactly is this "other application"? Why is it launching perl scripts? Why is memory such an issue?