1

What is the difference between a task and a pid? Inside of the /sys/fs/cgroup there a file called tasks which lists just pids,

$ ls /sys/fs/cgroup/*/tasks
/sys/fs/cgroup/blkio/tasks        /sys/fs/cgroup/net_cls,net_prio/tasks
/sys/fs/cgroup/cpuacct/tasks      /sys/fs/cgroup/net_cls/tasks
/sys/fs/cgroup/cpu,cpuacct/tasks  /sys/fs/cgroup/net_prio/tasks
/sys/fs/cgroup/cpuset/tasks       /sys/fs/cgroup/perf_event/tasks
/sys/fs/cgroup/cpu/tasks          /sys/fs/cgroup/pids/tasks
/sys/fs/cgroup/devices/tasks      /sys/fs/cgroup/rdma/tasks
/sys/fs/cgroup/freezer/tasks      /sys/fs/cgroup/systemd/tasks
/sys/fs/cgroup/memory/tasks

lsns also provides an option which does this,

-p, --task pid Display only the namespaces held by the process with this pid.

Why does cgroups call pid's tasks? Is there a distinction?

1

See man cgroups:

In cgroups v1, a distinction is drawn between processes and tasks. In this view, a process can consist of multiple tasks (more commonly called threads, from a user-space perspective, and called such in the remainder of this man page). In cgroups v1, it is possible to independently manipulate the cgroup memberships of the threads in a process.

The cgroups v1 ability to split threads across different cgroups caused problems in some cases. For example, it made no sense for the memory controller, since all of the threads of a process share a single address space. Because of these problems, the ability to independently manipulate the cgroup memberships of the threads in a process was removed in the initial cgroups v2 implementation, and subsequently restored in a more limited form (see the discussion of "thread mode" below).

Generally speaking, tasks are threads in Linux; see also /proc/*/task, and the hidden /proc entries for tids.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.