Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

systemd-cgls

Show the control groups (cgroups) as a tree with their processes (systemd-cgls), or their live resource use (systemd-cgtop).

Level
Everyday Linux
Group
Processes and jobs
Needs root
No
Package
systemd
Also called
systemd-cgtop

What it does

systemd puts every service, user session and container in its own cgroup, grouped in slices: system.slice, user.slice, machine.slice. systemd-cgls shows which process belongs to which service — useful when ps does not tell you where a process comes from. systemd-cgtop shows CPU, memory and I/O per cgroup, like top.

How to write it

systemd-cgls [OPTION]... [CGROUP...]
systemd-cgls [OPTION]... --unit|--user-unit [UNIT...]
systemd-cgtop [OPTION]... [GROUP]

Options 26

Most used

systemd-cgls

-u, --unit [UNIT]
Show the cgroup of these units.
--user-unit [UNIT]
Show user units.
-a, --all
Also empty cgroups.
-l, --full
Do not cut lines.
-k
Also kernel threads.
-x, --xattr=yes|no
Show extended attributes.
-c, --cgroup-id=yes|no
Show cgroup IDs.
-M, --machine=NAME
Show a container or VM.
--no-pager
Do not use a pager.
-h, --help
Show help.
--version
Show the version.

systemd-cgtop

-c, --order=cpu
Sort by CPU.
-m, --order=memory
Sort by memory.
-i, --order=io
Sort by I/O.
-t, --order=tasks
Sort by number of tasks.
-p, --order=path
Sort by path.
-b, --batch
Batch mode (for pipes).
-n, --iterations=N
Stop after N updates.
-d, --delay=SECONDS
Time between updates.
-1
One update only.
-r, --raw
Raw numbers.
-P
Count only user processes.
-k
Count all processes, also kernel threads.
--cpu=percentage|time
Show CPU as percent or time.
--depth=N
How deep the tree goes.
--recursive=yes|no
Include child cgroups in the numbers.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1The whole tree

    systemd-cgls --no-pager | head -25

    Slices, services and their processes.

  2. 2One service

    systemd-cgls -u httpd.service

    All processes of the web server, also CGI children.

  3. 3Where does this process come from?

    systemctl status 4123

    Shows the unit and cgroup of a PID.

  4. 4Your own session

    systemd-cgls -u user-1000.slice

    Everything you started.

  5. 5Live resource use per service

    systemd-cgtop

    Press m, c, i to sort.

  6. 6Sorted by memory, one snapshot

    systemd-cgtop -m -1 -b | head

    For a report.

  7. 7Container processes

    systemd-cgls -u machine.slice

    VMs and containers.

  8. 8Cgroup of a process directly

    cat /proc/4123/cgroup
    0::/system.slice/httpd.service

    cgroup v2 path.

  9. 9Limit a service with cgroups

    systemctl set-property httpd.service MemoryMax=1G CPUQuota=50%

    Resource limits are set on the cgroup.

  10. 10Find hidden processes of a service (security)

    systemd-cgls -u sshd.service

    A strange child (like a miner) under a service shows up here.

Exit codes

0Done.
1Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man systemd-cgls