Skip to content

Instantly share code, notes, and snippets.

@analogue
Last active December 15, 2023 01:00
Show Gist options
  • Save analogue/fae3d434432920eacb6add373a0609eb to your computer and use it in GitHub Desktop.
Save analogue/fae3d434432920eacb6add373a0609eb to your computer and use it in GitHub Desktop.
eatmemory
#!/bin/bash
# Spawn a process that eats memory by the gigabyte.
# Useful for testing ulimits and other such nonsense.
if [ $# -ne 1 ]; then
echo "Usage: $0 <gigabytes>"
exit 1
fi
gigabytes_to_allocate=$1
bytes_to_allocate=$((gigabytes_to_allocate * 1024 * 1024 * 1024))
echo "Allocating $gigabytes_to_allocate GB of memory...Ctrl-C to exit"
</dev/zero head -c $bytes_to_allocate | tail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment