Discussion:
cgroup.procs versus tasks (cgroups)
Kevin Wilson
2013-04-02 02:54:56 UTC
Permalink
Hi?
Any idea what is the difference "cgroup.procs" entry and "tasks"
entry of cgroup sysfs?
both represent pid lists.
I ran:
cat /sys/fs/cgroup/cpuset/cgroup.procs
and
cat /sys/fs/cgroup/cpuset/tasks
and entries of cgroup.procs appear in tasks.

However there are many more tasks than cgroup.procs:

cat /sys/fs/cgroup/cpuset/cgroup.procs | wc -l
153
cat /sys/fs/cgroup/cpuset/tasks | wc -l
383

Best
Kevin
Vlad Dogaru
2013-04-02 07:40:15 UTC
Permalink
Post by Kevin Wilson
Hi?
Any idea what is the difference "cgroup.procs" entry and "tasks"
entry of cgroup sysfs?
both represent pid lists.
cat /sys/fs/cgroup/cpuset/cgroup.procs
and
cat /sys/fs/cgroup/cpuset/tasks
and entries of cgroup.procs appear in tasks.
cat /sys/fs/cgroup/cpuset/cgroup.procs | wc -l
153
cat /sys/fs/cgroup/cpuset/tasks | wc -l
383
The difference you are seeing is because there are some multithreaded
processes in your cpuset. In the cgroup.procs file, each such process
apears only once (listed by its TGID). In the tasks file, each thread
appears once (listed by its PID).

Check the pidlist_array_load function in kernel/cgroup.c. procs is a
list of (unique) TGIDs, while tasks is a list of PIDs.

Hope this helps,
Vlad
Kevin Wilson
2013-04-02 13:46:24 UTC
Permalink
Hi,
Thanks a lot Vlad. This explains it.
- Does anybody know of a ps command (or a filter to ps command)
which will display only multithreaded
processes (list processes by TGID) ? (I know now about the option of
displaying cgroup.procs , but is something parallel can be done with ps ? )

rgs,
Kevin
Post by Vlad Dogaru
Post by Kevin Wilson
Hi?
Any idea what is the difference "cgroup.procs" entry and "tasks"
entry of cgroup sysfs?
both represent pid lists.
cat /sys/fs/cgroup/cpuset/cgroup.procs
and
cat /sys/fs/cgroup/cpuset/tasks
and entries of cgroup.procs appear in tasks.
cat /sys/fs/cgroup/cpuset/cgroup.procs | wc -l
153
cat /sys/fs/cgroup/cpuset/tasks | wc -l
383
The difference you are seeing is because there are some multithreaded
processes in your cpuset. In the cgroup.procs file, each such process
apears only once (listed by its TGID). In the tasks file, each thread
appears once (listed by its PID).
Check the pidlist_array_load function in kernel/cgroup.c. procs is a
list of (unique) TGIDs, while tasks is a list of PIDs.
Hope this helps,
Vlad
V***@vt.edu
2013-04-02 18:14:08 UTC
Permalink
Post by Kevin Wilson
Hi,
Thanks a lot Vlad. This explains it.
- Does anybody know of a ps command (or a filter to ps command)
which will display only multithreaded
processes (list processes by TGID) ? (I know now about the option of
displaying cgroup.procs , but is something parallel can be done with ps ? )
Have you tried 'ps -m' and friends? Though it doesn't do exactly
what you wanted and *only* display multithreaded, you need to do some
post-processing:

$ ps max
...
928 ? - 0:00 /sbin/auditd -n
- - S<sl 0:00 -
- - S<sl 0:00 -
940 ? - 0:00 /sbin/audispd
- - S<sl 0:00 -
- - S<sl 0:00 -
951 ? - 0:00 /usr/sbin/abrtd -d -s
- - Ss 0:00 -
960 ? - 0:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
- - Ss 0:00 -

If there's 2 or more '- -' after the process entry, it's multi=threaded.

Note however that as far as the kernel is concerned, a single-threaded
process is handled by the code as a multi-threaded that happens to have
only one thread at the moment. In other words, thinking that single and
multi threaded is different in some mystical way will probably end up
causing trouble for you...
Rami Rosen
2013-04-03 03:46:48 UTC
Permalink
Hi,

BTW, for a given thread group with a specified TGID, you can view all the
threads PIDs in that thread group thus:
pstree -p TGID

and:
pstree TGID
will give one line; It visually merges identical branches by putting
them in square brackets and prefixing them with the repetition count.

Regards,
Rami Rosen
http://ramirose.wix.com/ramirosen
Post by V***@vt.edu
Post by Kevin Wilson
Hi,
Thanks a lot Vlad. This explains it.
- Does anybody know of a ps command (or a filter to ps command)
which will display only multithreaded
processes (list processes by TGID) ? (I know now about the option of
displaying cgroup.procs , but is something parallel can be done with ps ? )
Have you tried 'ps -m' and friends? Though it doesn't do exactly
what you wanted and *only* display multithreaded, you need to do some
$ ps max
...
928 ? - 0:00 /sbin/auditd -n
- - S<sl 0:00 -
- - S<sl 0:00 -
940 ? - 0:00 /sbin/audispd
- - S<sl 0:00 -
- - S<sl 0:00 -
951 ? - 0:00 /usr/sbin/abrtd -d -s
- - Ss 0:00 -
960 ? - 0:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg -xD
- - Ss 0:00 -
If there's 2 or more '- -' after the process entry, it's multi=threaded.
Note however that as far as the kernel is concerned, a single-threaded
process is handled by the code as a multi-threaded that happens to have
only one thread at the moment. In other words, thinking that single and
multi threaded is different in some mystical way will probably end up
causing trouble for you...
_______________________________________________
Kernelnewbies mailing list
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Loading...