Bottom line: it's probably not practical or useful.
An operating system is the only thing that can load an application image and do all the work required to run it. Actually loading the image into memory is a small part of the work that goes on to prep an image for running. You may find that running your app out of a RAM disk helps a little - about as much as "loading it into a variable".
Perl reduces RSI - it saves typing
| [reply] |
What you are trying to do isn't possible, really.
However, if you want to avoid the cost of re-starting an app all the time you might be able to do that. It would depend on what program you are running, but if the program takes it's input from a file, pipe, or standard input, you can start the program and then feed it data as you get it or as needed. (Well, file may or may not work depending on your OS and the program, but the others should work well.)
| [reply] |
What do you mean by "loading an application into a variable name"? You probably don't mean:
my $application = "nmap";
my @args = qw !--stylesheet nmap.xsl!;
while (1) {
system $application, @arg and die;
}
| [reply] [d/l] |
I meant something along the lines of:
my $application = "nmap";
my $app_var = undef;
my $app_options = " -sT -p 80 $IP";
if ( -f $application ){
open(APP, "<$application");
binmode APP;
while( <APP> ){
$app_var .= $_;
}
}
while{1}{
#Run application loaded into variable...
eval { $app_var $app_options };
}
It probably makes much better sense to copy the application to ramdisk and just run it from there. Thanks!! I would like to hear anyones' ideas on the subject, though.
Thanks!
-R1n0
| [reply] |
| [reply] |
Well, that would require either writing a kernel module that can run Perl code and do all this from kernel space, or writing a Perl extension that can run binaries.
Neither seem practical to me; it's a lot of work and I cannot really see much gain.
But if you pull it off, I'd be very surprised if OSCON rejects your talk proposal. ;-)
| [reply] |
A completely different approach would be to use my execute code which I reposted here. Basically, it will run a command line application without a shell, so there's less overhead. It also captures the output, so it is 'loading to a variable' which might fit your request better. HTH, SSF.
sub execute { # execute a command without shell but with timeout
my ($cmd,@args)=@_;
my $timeout=15; # seconds
my ($result,$pid,$i);
if ($args[$#args]=~/^--?timeout=(\d+)$/i) { # or pass as last arg
$timeout=$1;
pop @args;
}
$i=index($cmd,' '); # args appended to command?
if ($i>-1) {
unshift @args,split(/\s+/,substr($cmd,$i+1)); # could be more
+than one
$cmd=substr($cmd,0,$i);
}
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required
local($/)=undef;
alarm $timeout;
$pid=open(CMD,'-|',$cmd,@args); # run without shell overhead
if ($pid) {
$result=<CMD>;
close CMD;
} else {
alarm 0;
}
alarm 0;
};
if ($@) {
die $@ unless $@ eq "alarm\n"; # propagate unexpected errors
}
$result;
}
| [reply] [d/l] |