in reply to Re: How to reduce memory by killing redundant perl executables
in thread How to reduce memory by killing redundant perl executables
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