Home > Mobile >  Start rust program in cgroupv2
Start rust program in cgroupv2

Time:01-05

I wrote a BPF sockops program and attach it to a cgroupv2. This applies the BPF program to all sockets from programs in that cgroupv2. How do I go about running a Rust program in this cgroupv2?

The Rust program is creating a socket to which I want the sockops program to be applied. Unfortunately I can´t find a way to directly attach the BPF program to the socket because no rust library seems to support the required syscalls to load and attach sockops programs directly to sockets. That´s why I want to use control groups instead.

CodePudding user response:

The easiest way is to write the process pid into the cgroup's cgroup.procs file. This should be done fairly early in the process to make sure resources are attributed to the right group. Alternatively you can wrap the command in cgexec

  • Related