How to write a C or C++ program to act as a memory and CPU cycle filler?

I want to test a program's memory management capabilities, for example (say, program name is director)

  1. What happens if some other processes take up too much memory, and there is too less memory for director to run? How does director behave?
  2. What happens if too many of the CPU cycles are used by some other program while director is running?
  3. What happens if memory used by the other programs is freed after sometime? How does director claim the memory and start working at full capabilities. etc.

I'll be doing these experiments on a Unix machine. One way is to limit the amount of memory available to the process using ulimit, but there is no good way to have control over the CPU cycle utilization.

I have another idea. What if I write some program in C or C++ that acts as a dynamic memory and CPU filler, i.e. does nothing useful but eats up memory and/or CPU cycles anyways?

  • I need some ideas on how such a program should be structured. I need to have dynamic(runtime) control over memory used and CPU used.
  • I think that creating a lot of threads would be a good way to clog up the CPU cycles. Is that right?

Is there a better approach that I can use?

Any ideas/suggestions/comments are welcome.

10
задан Lazer 31 August 2010 в 17:25
поделиться

2 ответа

http://weather.ou.edu/~apw/projects/stress/

Stress — намеренно простой генератор рабочей нагрузки для систем POSIX. Он накладывает на систему настраиваемое количество ресурсов ЦП, памяти, операций ввода-вывода и диска. Он написан на C и является бесплатным программным обеспечением под лицензией GPLv2.

Функциональность, которую вы ищете, пересекается с набором функций «инструментов тестирования». Также проверьте http://ltp.sourceforge.net/tooltable.php.

10
ответ дан 4 December 2019 в 00:22
поделиться

Если у вас одно ядро, этого достаточно, чтобы загрузить ЦП:

while ( true ) {
   x++;
} 

Если у вас много ядер, вам нужен поток на ядро.

Вы можете сделать его непостоянным голодным, добавив несколько снов.

Что касается памяти, просто выделяйте много.

1
ответ дан 4 December 2019 в 00:22
поделиться
Другие вопросы по тегам:

Похожие вопросы: