### Execute command with memory limit Source: https://github.com/shadyfennec/memlimit/blob/main/README.md Example of running a command with a 16GB memory limit while tracking child processes. ```bash memlimit -c 16GB cargo install ripgrep --force ``` -------------------------------- ### CI/CD Pipeline Integration Source: https://context7.com/shadyfennec/memlimit/llms.txt Example of using memlimit within a shell script to handle test execution and exit codes. ```bash #!/bin/bash # ci-script.sh # Run tests with memory limit if memlimit -c 4GiB npm test; then echo "Tests passed within memory limit" else exit_code=$? echo "Tests failed or exceeded memory limit (exit code: $exit_code)" exit $exit_code fi ``` -------------------------------- ### Build System Memory Limits Source: https://context7.com/shadyfennec/memlimit/llms.txt Use memlimit to constrain resource-intensive build processes. ```bash # Limit Rust compilation memlimit -c 8GiB cargo build --release # Limit C++ compilation with make memlimit -c 16GB make -j$(nproc) # Limit webpack bundling memlimit -c 4GiB npm run build # Limit Docker build memlimit -c 8GB docker build -t myimage . ``` -------------------------------- ### Protect development environment Source: https://context7.com/shadyfennec/memlimit/llms.txt Apply memory constraints to common development tools and services to prevent resource exhaustion. ```bash # Limit IDE language servers memlimit -c 2GiB rust-analyzer # Limit development server memlimit -c 1GiB npm run dev # Limit database for local development memlimit 512MiB postgres -D /var/lib/postgresql/data ``` -------------------------------- ### Basic Memory Limit Usage Source: https://context7.com/shadyfennec/memlimit/llms.txt Run a command with a specified memory limit using SI, binary, or raw byte units. ```bash # Limit a process to 500MB of memory memlimit 500MB ./my-program # Limit to 1GB using binary units (1024-based) memlimit 1GiB ./my-program # Limit using raw bytes memlimit 536870912 ./my-program ``` -------------------------------- ### Build with memory limit Source: https://context7.com/shadyfennec/memlimit/llms.txt Enforce a memory limit on a build command using the -c flag. ```bash memlimit -c 8GiB npm run build || exit 1 ``` -------------------------------- ### Monitor Virtual Memory Source: https://context7.com/shadyfennec/memlimit/llms.txt Use the --virtual flag to track virtual memory usage instead of the default resident set size (RSS). ```bash # Monitor virtual memory usage with 32GB limit memlimit --virtual 32GB ./memory-intensive-app # Combine with children monitoring memlimit -c --virtual 16GiB java -jar application.jar ``` -------------------------------- ### Memory limit architecture validation Source: https://github.com/shadyfennec/memlimit/blob/main/README.md Demonstration of how memlimit handles memory limits that exceed the maximum addressable size of the current architecture. ```bash $ # On a 64-bit computer $ memlimit 15EiB echo hello hello $ memlimit 16EiB echo hello error: invalid value '16EiB' for '': amount '16EiB' too big for current architecture ``` -------------------------------- ### Monitor Child Processes Source: https://context7.com/shadyfennec/memlimit/llms.txt Use the -c or --children flag to monitor the aggregate memory consumption of a process and all its descendants. ```bash # Monitor cargo and all its child processes with 16GB limit memlimit -c 16GB cargo install ripgrep --force # Monitor a build process and all spawned compilers memlimit -c 8GiB make -j8 # Monitor npm install with all its child processes memlimit --children 4GB npm install ``` -------------------------------- ### Supported Memory Units Source: https://context7.com/shadyfennec/memlimit/llms.txt Memory limits can be defined using raw bytes, decimal (SI) units, or binary units. Ensure no whitespace exists between the number and the unit. ```bash # Raw bytes memlimit 1048576 ./program # 1,048,576 bytes # Bytes with explicit suffix memlimit 1048576B ./program # Same as above # Decimal units (base 1000) memlimit 1K ./program # 1,000 bytes memlimit 1KB ./program # 1,000 bytes memlimit 1M ./program # 1,000,000 bytes memlimit 1MB ./program # 1,000,000 bytes memlimit 1G ./program # 1,000,000,000 bytes memlimit 1GB ./program # 1,000,000,000 bytes memlimit 1T ./program # 1,000,000,000,000 bytes memlimit 1TB ./program # 1,000,000,000,000 bytes # Binary units (base 1024) memlimit 1Ki ./program # 1,024 bytes memlimit 1KiB ./program # 1,024 bytes memlimit 1Mi ./program # 1,048,576 bytes memlimit 1MiB ./program # 1,048,576 bytes memlimit 1Gi ./program # 1,073,741,824 bytes memlimit 1GiB ./program # 1,073,741,824 bytes memlimit 1Ti ./program # 1,099,511,627,776 bytes memlimit 1TiB ./program # 1,099,511,627,776 bytes ``` -------------------------------- ### Architecture Memory Limits Source: https://context7.com/shadyfennec/memlimit/llms.txt Memory limits are constrained by the maximum addressable memory of the host architecture. ```bash # On a 64-bit system - works fine (under 2^64 bytes) memlimit 15EiB echo hello # Output: hello # On a 64-bit system - fails (exceeds 2^64 bytes) memlimit 16EiB echo hello # Output: error: invalid value '16EiB' for '': amount '16EiB' too big for current architecture ``` -------------------------------- ### Exit Code Propagation Source: https://context7.com/shadyfennec/memlimit/llms.txt memlimit preserves the exit code of the monitored process, allowing for integration into scripts and CI/CD pipelines. ```bash # Successful command - exits with 0 memlimit 1GB echo "Hello, World!" echo $? # Output: # Hello, World! # 0 # Failed command - preserves non-zero exit code memlimit 1GB ls /nonexistent-directory echo $? # Output: # ls: cannot access '/nonexistent-directory': No such file or directory # 2 # Process killed due to memory limit - non-zero exit code memlimit 10MB ./memory-hog echo $? # Output: # memlimit: memory usage = 15728640 bytes, higher than limit of 10000000, killed. # (exit code depends on OS, typically non-zero) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.