Skip to content

Instantly share code, notes, and snippets.

@aufi
Last active March 8, 2018 17:31
Show Gist options
  • Save aufi/04103589aaf3d14b973880967266fd37 to your computer and use it in GitHub Desktop.
Save aufi/04103589aaf3d14b973880967266fd37 to your computer and use it in GitHub Desktop.
memory consumer
FROM centos:7
COPY memconsumer /bin/memconsumer
ENTRYPOINT memconsumer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main()
{
int num, i, *ptr = 0;
printf("Starting memory consumer..\n");
for(i = 0; i < 9999; ++i)
{
printf("Increasing allocated memory..\n");
ptr = (int*) malloc(i * 1048576);
memset(ptr, 1, i*104857);
sleep(2);
}
free(ptr);
return 0;
}

memconsumer for testing purposes

published at https://hub.docker.com/r/aufi/memconsumer/

example

[maufart@nb 04103589aaf3d14b973880967266fd37]$ docker build . -t memconsumer Sending build context to Docker daemon 58.37kB Step 1/2 : from centos:7 ---> ff426288ea90 Step 2/2 : COPY memconsumer /bin/memconsumer ---> Using cache ---> b7cf1976739b Successfully built b7cf1976739b Successfully tagged memconsumer:latest [maufart@nb 04103589aaf3d14b973880967266fd37]$ [maufart@nb 04103589aaf3d14b973880967266fd37]$ [maufart@nb 04103589aaf3d14b973880967266fd37]$ docker run --memory 100m -it memconsumer [root@6f6174d12a07 /]# exit exit [maufart@nb 04103589aaf3d14b973880967266fd37]$ docker run --memory 100m -it memconsumer memconsumer Starting memory consumer.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. Increasing allocated memory.. [maufart@nb 04103589aaf3d14b973880967266fd37]$ echo $? 137

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment