Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Spawning processes from scalars

by fluffyvoidwarrior (Monk)
on Apr 25, 2011 at 14:30 UTC ( #901204=note: print w/replies, xml ) Need Help??


in reply to Re: Spawning processes from scalars
in thread Spawning processes from scalars

Oops, sorry, Ubuntu server 10.04 64bit. I have no idea how to do it and can't find any info anywhere so I thought it probably wasn't a realistic option. The best I can think of is to use a ram disk and then wipe it.

Replies are listed 'Best First'.
Re^3: Spawning processes from scalars
by Corion (Pope) on Apr 25, 2011 at 15:36 UTC

    There only is the hard way of copying your process (via fork), patching up your scalar like your OS would, and then jumping (via XS or assembly code) to the start of the process.

    On Solaris, the /tmp "directory" resides in RAM and is not flushed to disk - if it really is a pressing matter of performance, you could mount /tmp as a ramdisk on your system as well. Note that for security reasons, programs in /tmp often are not allowed to execute, because malicious code uses this directory as a vector to drop files. So you might want to set up a directory similar but different from /tmp.

      Thanks. Not really an option. So it's plan B then...
Re^3: Spawning processes from scalars
by chrestomanci (Priest) on Apr 25, 2011 at 19:51 UTC

    That is fairly easy to do under ubuntu. Firstly create a tmpfs partition of a suitable size, and define a mount point.

    In your /etc/fstab:

    none /binary_exec tmpfs size=2G 0 0

    Or on the command line (as root)

    mount none /binary_exec -t tmpfs -o size=2G

    The mount point for the tmpfs partition must be created as a directory first. It need not be in the root of your file-system.

    You can be quite generous with the size of the tmpfs volume, as it is only the upper limit for the file-system, so you won't consume 2G of RAM just by creating the file-system, only the total size of the files you write there, and in any case file data in tmpfs will get swapped out if the fs is large enough to cause memory pressure.

    Once you have created the temporary partition, you can write your executable binary there from your perl scalar in the normal way. It should be very quick as you are just copying bytes from one part of ram to another. From there it is trivial to run the executable. You can also delete files just as quickly.

      Thanks. I'll give that a go since it is effectively the same thing.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://901204]
help
Chatterbox?
[LanX]: choroba: subversive (as usual ;)
[james28909]: i dunno, if i didnt have so little experience in linux i would swap. but it would be to much of a learning curve for me right now.
[choroba]: Low-end is defined as the Perl that generates millions of income
[choroba]: sorry, that's high-end, of coursse
[choroba]: low end, in my talk, will be code that "we don't touch because it works" and noone knows why
[choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution
[choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe...
[choroba]: LanX: That's the heritage, I can't do anything else
[RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible"
[marto]: choroba sounds interesting

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2017-05-22 21:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?