Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://901204]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2018-06-18 19:42 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.