Cross-platform CLI: holder keeps CPU/memory usage at target levels; watch monitors a process and runs shell commands when thresholds are met.
- System-wide or per-core CPU hold
- Memory hold by percentage or fixed size
- CPU / memory sine-wave modes
- Process CPU and memory thresholds with AND/OR logic
- CLI flags and JSON config (flags override config)
- Windows, Linux, macOS
.
├── cmd/resource-holder/ # main entrypoint
├── internal/cli/ # Cobra commands
├── internal/config/ # config loading
├── internal/platform/ # OS-specific code
├── internal/resource/ # hold & watch logic
└── examples/ # sample JSON configs
Build: make build → bin/resource-holder. Cross-compile: make build-all → dist/resource-holder_<os>_<arch>.
Requires Go 1.22+.
git clone https://github.com/soraclub/resource-holder.git
cd resource-holder
go mod download
make buildEquivalent:
go build -o bin/resource-holder ./cmd/resource-holderInstall to $PATH:
make installAfter make build or make install, commands below use resource-holder (or ./bin/resource-holder during local dev).
Hold resources at the target when usage is below the target; do nothing when already above.
resource-holder holder -c 50%
resource-holder holder -m 1G
resource-holder holder -c 50% -m 1G -i 2s
resource-holder holder -f examples/holder_config.json
resource-holder holder -c 50% --cpu-sine --cpu-amplitude 20% --cpu-period 30s
resource-holder holder -m 1G --mem-sine --mem-amplitude 200MB --mem-period 30sMonitor a PID and run operations when thresholds match. Use {PID} in command strings.
resource-holder watch -p 1234 -c ">50%" -o "echo process {PID} over limit"
resource-holder watch -p 1234 -m ">1G" -o "kill {PID}"
resource-holder watch -p 1234 -c ">50%" -m ">1G" -l or -o "kill {PID}"
resource-holder watch -p 1234 -c ">50%" -o "kill {PID}" -t 1
resource-holder watch -f examples/watch_config.jsonJSON with top-level holder or watch. Samples in examples/:
| File | Description |
|---|---|
holder_config.json |
CPU (optional per-core), memory, interval |
holder_sine_config.json |
holder with CPU sine wave |
watch_config.json |
thresholds, logic, operations, trigger limit |
Pass -f / --config. For field details and defaults, see:
resource-holder holder --help
resource-holder watch --helpmake test
make vet
make lint # requires golangci-lint locally
make build-allSee CONTRIBUTING.md, CHANGELOG.md, and RELEASE.md (GitHub setup, main, tagging).