A lightweight, custom OS-level container engine written in C++. It spawns processes into their own PID and mount namespaces, enforces memory/CPU limits via cgroups and reports live resource usage back to the CLI. The project was made mainly for the purpose of teaching myself important OS concepts and how other fully-fledged container engines work.
slved: background daemon (systemd service). Listens for commands over a unix domain socket, spawns and isolates containers, enforces resource limits and reaps exited processes.slvectl: CLI client. Sendsstart/stop/statuscommands to the daemon over the socket mentioned above.- Isolation:
clone()withCLONE_NEWPID | CLONE_NEWNS, a private mount namespace withpivot_root, a fresh/procand minimal/dev, and a read-only rootfs. - Resource limits: cgroups v2 (
memory.max,cpu.max) applied before the container's process is ever ran.
- Linux with cgroups v2 mounted at
/sys/fs/cgroup - CMake >= 3.16, a C++17 compiler
- systemd (for running
slvedas a service)
git clone <repo-url>
cd mini-lve
cmake -S . -B build
cmake --build buildsudo ./scripts/setup.sh
sudo systemctl start slved# Launch a container
sudo slvectl start -n myapp -m 128 -c 50 -p /bin/echo -a "hello"
# Check running containers' live memory/CPU usage
sudo slvectl status
# Stop a container (SIGTERM, escalates to SIGKILL after a grace period)
sudo slvectl stop -n myappRun slvectl with no arguments for full flag documentation.
A quick test that confirms the memory limit is actually enforced by launching a resource hogging process:
sudo systemctl start slved
sudo ./scripts/memlimit_test.shCMakeLists.txt
include/
protocol.hpp
manager.hpp
scripts/
setup.sh
slved.service
mem_hog.cpp
memlimit_test.sh
src/
client/ # slvectl
common/ # socket_utils
daemon/ # slved, CgroupManager