unix_95054 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I know that it is possible to generate dummy/fake CPU load using perl. Here is how to do that:
perl -e 'while (--$ARGV[0] and fork) {}; while () {}' 4
Could someone please let me know how to generate fake or dummy load on memory for a Unix server? This will be used for a small test. Thanks, Unix Lover

Replies are listed 'Best First'.
Re: How to generate 'fake' memory load?
by kyle (Abbot) on Aug 04, 2008 at 19:32 UTC

    You just want to allocate a lot of memory?

    perl -e '$m = "x" x 1_000_000; sleep 120';

    (Holds its memory for two minutes and exits.)

Re: How to generate 'fake' memory load? (hogs)
by tye (Sage) on Aug 04, 2008 at 20:12 UTC

    See also: one-liner hogs. There are at least two flavors of "memory load". Allocating a large string mostly just ends up consuming swap space. Continually updating the contents of a large string can consume physical memory (if the process doesn't just lose out in the fight to keep access to that limited resource).

    - tye        

      Reading can do the same thing as updating. For instance try the following to allocate about 10 MB of memory and actually keep it active:
      perl -e '$_ = "x" x 10_000_000; $_ .= "y"; sleep 1 while /y/;'
      Update: kyle caught a typo where I switched variable names. Fixed.
Re: How to generate 'fake' memory load?
by Joost (Canon) on Aug 04, 2008 at 20:13 UTC