Menu Close

16.4. 列出 systemd 单元

以下流程描述了如何使用 systemd 系统和服务管理器列出其单元。

步骤

  • 要列出系统中的所有活跃单元,执行 # systemctl 命令,终端将返回类似以下示例的输出:

    # systemctl
    UNIT                                                LOAD   ACTIVE SUB       DESCRIPTION
    …​
    init.scope                                          loaded active running   System and Service Manager
    session-2.scope                                     loaded active running   Session 2 of user jdoe
    abrt-ccpp.service                                   loaded active exited    Install ABRT coredump hook
    abrt-oops.service                                   loaded active running   ABRT kernel log watcher
    abrt-vmcore.service                                 loaded active exited    Harvest vmcores for ABRT
    abrt-xorg.service                                   loaded active running   ABRT Xorg log watcher
    …​
    -.slice                                             loaded active active    Root Slice
    machine.slice                                       loaded active active    Virtual Machine and Container Slice system-getty.slice                                                                       loaded active active    system-getty.slice
    system-lvm2\x2dpvscan.slice                         loaded active active    system-lvm2\x2dpvscan.slice
    system-sshd\x2dkeygen.slice                         loaded active active    system-sshd\x2dkeygen.slice
    system-systemd\x2dhibernate\x2dresume.slice         loaded active active    system-systemd\x2dhibernate\x2dresume>
    system-user\x2druntime\x2ddir.slice                 loaded active active    system-user\x2druntime\x2ddir.slice
    system.slice                                        loaded active active    System Slice
    user-1000.slice                                     loaded active active    User Slice of UID 1000
    user-42.slice                                       loaded active active    User Slice of UID 42
    user.slice                                          loaded active active    User and Session Slice
    …​
    • UNIT - 反映控制组群层次结构中的单元位置的单元名称。与资源控制相关的单元是 slicescopeservice
    • LOAD - 指示单元配置文件是否已正确加载。如果单元文件加载失败,该字段包含状态 error 而不是 loaded。其他单元负载状态为: stubmergemasked
    • ACTIVE - 高级单元激活状态,即 SUB 的一般化。
    • SUB - 低级单元激活状态。可能的值的范围取决于单元类型。
    • DESCRIPTION - 单元内容和功能的描述。
  • 要列出不活跃单元,请执行:

    # systemctl --all
  • 要限制输出中的信息量,请执行:

    # systemctl --type service,masked

    --type 选项需要一个以逗号分隔的单元类型列表,如 serviceslice,或者单元载入状态,如 loadedmasked

其他资源