skip to Main Content

I am trying to write a pid to a manually created cgroup but I am unable to do so.

While writing, I am getting the following error:

open /sys/fs/cgroup/pids/scratch-container-cgroup0049cba7-8f9e-42ec-9646-9b1babbfebc3/cgroups.procs: permission denied

The file has the following permissions:

[~~]$ ls -l cgroup.procs
-rw-r--r-- 1 root root 0 Feb 14 23:27 cgroup.procs
[~~]$

The code that I am using to write it as follows in Go

    procs := filepath.Join(containerCgroupPath, "cgroups.procs")
    currentPid := strconv.Itoa(os.Getpid())
    log.Printf("current pid is %s", currentPid)
    if err := ioutil.WriteFile(procs, []byte(currentPid), 0777); err != nil {
        return err
    }

However, using bash also gives out the same error.

sudo echo "100" > cgroup.procs 
bash: cgroup.procs: Permission denied

I am not sure what I am missing about cgroups here that could be used to write. I am on Centos that is running systemd.

I am able to write to pids.max and notify_on_release

I will really appreciate insights here.

3

Answers


  1. Can’t speak about the go code, but the problem in bash is most likely down to this:

    How do I use sudo to redirect output to a location I don't have permission to write to?

    If that doesn’t help you, please also check that you have permissions to write to the cgroup.procs file in the common parent of process 100 (echo /proc/100/cgroup) and the cgroup where you’re moving it to (/sys/fs/cgroup/pids/scratch-container-cgroup0049cba7-8f9e-42ec-9646-9b1babbfebc3/).

    Login or Signup to reply.
  2. The correct file name in your code should be "cgroup.procs" instead of "cgroups.procs"

    Login or Signup to reply.
  3. I have encountered the same issue. I tried the following and it works

    echo "100" | sudo tee cgroup.procs 
    

    But I could not explain why.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search