cpulimit

Install

cpulimit builds with GNU make and any C99 compiler. It has no dependencies beyond the C library (and libkvm on FreeBSD).

Build and install

git clone https://github.com/denji/cpulimit.git
cd cpulimit
make                      # binary in build/cpulimit (copied to src/cpulimit)
make check                # unit, CLI and integration tests
sudo make install         # /usr/local/bin/cpulimit and the man page

On FreeBSD, OpenBSD, NetBSD and illumos the GNU make is gmake (pkg install gmake, pkg_add gmake); the plain make of those systems cannot read the Makefile.

Variables

VariableDefaultMeaning
PREFIX/usr/localinstall prefix; BINDIR and MANDIR derive from it
DESTDIRemptystaging root for packagers
CC, CFLAGS, CPPFLAGS, LDFLAGS-O2 -gyours are never overridden: the flags the program needs (-D_GNU_SOURCE, -Wall -Wextra) are kept apart from them
BUILDbuildobject and output directory; the build is non-recursive and rebuilds when the compiler or any flag changes
WERROR=1offturn warnings into errors (what CI uses)
STATIC_CCmusl-gcccompiler for make static

make install never calls sudo itself. make uninstall removes what it installed.

Static binary

make static STATIC_CC=musl-gcc    # build/static/cpulimit, no shared libraries
make static-install

The static build uses its own object directory, so it never mixes with a dynamic one.

Release binaries

Tagged releases are meant to carry static musl binaries (x86_64, aarch64, armv7, i686, ppc64le, s390x, riscv64) with a .sha256 file each. The release workflow has not produced a release yet, so look at the releases page to see whether one exists for your version before relying on it. How to check a download: Releases.

Notes for packagers

  • The man page is hand written (man/cpulimit.1) and installed by make install; make man only checks that it formats.
  • make check needs /proc (Linux) or the platform's process interface; the integration tests start real processes. SKIP_INTEGRATION=1 runs only the unit tests, and CPULIMIT_SKIP_TIMING=1 skips the checks that depend on CPU accounting being accurate (emulated CPUs, busy shared builders).
  • The version is in three places that a test keeps equal: src/cli/cli.c, the man page header and the top of CHANGELOG.md.

Which systems are tested

All of Linux (glibc and musl), macOS, FreeBSD, OpenBSD and NetBSD have a process iterator; the honest version of how much each was run is on the platforms page. Short form: Linux is tested heavily, macOS and OpenBSD run the unit tests in CI, FreeBSD and the other BSDs are built and report their results to a non-gating workflow, and NetBSD and Solaris/illumos have not yet been confirmed on a real system.