How to consume memory and load CPU?

How to consume memory and load CPU?

Post by Praveen Shett » Fri, 20 Jul 2001 16:06:28



Hello,

I am new to Linux and I am digging for ways to
comsume memory and load CPU by any OS related process?
Any guesses on which would be the safe and robust way to do it?

Thanks.
Praveen.

 
 
 

How to consume memory and load CPU?

Post by Bohdan Vlasyu » Fri, 20 Jul 2001 17:01:34



> I am new to Linux and I am digging for ways to comsume memory and
> load CPU by any OS related process?  Any guesses on which would be
> the safe and robust way to do it?

int main()
{
  int i=1;
  while(i) {
    i++;
    i--;
    malloc(i);
  }

Quote:}

run this program like this

nice -n 19 programname

It's pretty nice way. Buy why might you need it??

 
 
 

How to consume memory and load CPU?

Post by Praveen Shett » Fri, 20 Jul 2001 18:53:18


Thanks.
I am able to see the memory consumed
and the CPU usage by using the "top" command,
however the programme gets killed when the memory gets
low.Is there any way to maintain this state and not let the
programme get killed?


>> I am new to Linux and I am digging for ways to comsume memory and
>> load CPU by any OS related process?  Any guesses on which would be
>> the safe and robust way to do it?

>int main()
>{
>  int i=1;
>  while(i) {
>    i++;
>    i--;
>    malloc(i);
>  }
>}

>run this program like this

>nice -n 19 programname

>It's pretty nice way. Buy why might you need it??

 
 
 

How to consume memory and load CPU?

Post by mlw » Fri, 20 Jul 2001 20:53:18


That really isn't a good way. That type of process would get killed by the OS
eventually.

What you could do is:

int main(int argc, char **argv)
{
        int i;
        int cb = atoi(argv[1])*1024*1024;
        void * p = malloc(cb);

        for(i=0; 1; i++)
        {
                memset(p, i, cb);
        }      

Quote:}

Having the program memset the memory, forces the OS to actually allocate it.
When you malloc, you do not get memory, it is only when you use it does it get
assigned to you.

So, then you run the program:

cc fubar.c

./a.out 32 &
./a.out 32 &

That will allocate a total of 64M (Add as many as you like, or allocate bigger
chunks) and fully load the system.

"killall a.out" will stop it.



> > I am new to Linux and I am digging for ways to comsume memory and
> > load CPU by any OS related process?  Any guesses on which would be
> > the safe and robust way to do it?

> int main()
> {
>   int i=1;
>   while(i) {
>     i++;
>     i--;
>     malloc(i);
>   }
> }

> run this program like this

> nice -n 19 programname

> It's pretty nice way. Buy why might you need it??

--
5-4-3-2-1 Thunderbirds are GO!
------------------------
http://www.mohawksoft.com
 
 
 

How to consume memory and load CPU?

Post by Bohdan Vlasyu » Fri, 20 Jul 2001 20:52:15



> I am able to see the memory consumed and the CPU usage by using the
> "top" command, however the programme gets killed when the memory
> gets low.Is there any way to maintain this state and not let the
> programme get killed?

I think there is, but it'd be better to tell us why may you need this,
since solutions may vary.
 
 
 

How to consume memory and load CPU?

Post by Praveen Shett » Sat, 21 Jul 2001 19:49:52


Thanks, m|w
 
 
 

How to consume memory and load CPU?

Post by Praveen Shett » Thu, 26 Jul 2001 19:16:41


Hi,

what happens when we run with "./a.out 32 &"
Whats the significance of "."?

BR;
Praveen.


>That really isn't a good way. That type of process would get killed by the
OS
>eventually.

>What you could do is:

>int main(int argc, char **argv)
>{
> int i;
> int cb = atoi(argv[1])*1024*1024;
> void * p = malloc(cb);

> for(i=0; 1; i++)
> {
> memset(p, i, cb);
> }
>}

>Having the program memset the memory, forces the OS to actually allocate
it.
>When you malloc, you do not get memory, it is only when you use it does it
get
>assigned to you.

>So, then you run the program:

>cc fubar.c

>./a.out 32 &
>./a.out 32 &

>That will allocate a total of 64M (Add as many as you like, or allocate
bigger
>chunks) and fully load the system.

>"killall a.out" will stop it.

 
 
 

How to consume memory and load CPU?

Post by Harry Georg » Thu, 26 Jul 2001 22:48:29



> Hi,

> what happens when we run with "./a.out 32 &"
> Whats the significance of "."?

> BR;
> Praveen.

Technically, the "." assures you are in the current dir, so you don't
accidentally get some a.out elsewhere on your path.  Culturally, it
goes like this:

If "." is on your path (thus allowing you to say just "a.out"), then
you are vulnerable to a security problem: You download a tarball
(collection of files), open it, and there is a file called "ls" in the
collection.  You innocenently try to see what files have arrived and
type "ls".  The evil "ls" in your current directory, which was just
downloaded, is found and run.  It proceeds to send your passwd file
across the internet and then destroy your harddisk...

So it is a good idea to *not* have "." on your path.  Once you've made
that choice, whenever you really do want to run a file in the current
dir, you have to give its path explicitly, as "./".

--

The Boeing Company          Renton:  (425) 237-6915
P. O. Box 3707  02-CA       Everett: (425) 266-3868
Seattle, WA 98124-2207      Page:    (425) 631-8803  

 
 
 

How to consume memory and load CPU?

Post by Praveen Shett » Fri, 03 Aug 2001 00:47:34


Well after generating the CPU load, how can I match it to the desired
level?
Using the top command, we can see the % of CPU engaged, but
how it can be controlled to match the desired load?
It looks obvious that some feedback loop has to be there,
but any pointers on this will be helfpul.

BR,
Praveen.