Linux ps 命令导致AOSP编译失败

简介: Linux ps 命令导致AOSP编译失败

平台


Ubuntu 20.04


概述


下载了AOSP代码尝试编译, 谁料出师未捷…


$. build/envsetup.sh 
error: conflicting format options
Usage:
 ps [options]
 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.
For more details see ps(1).
WARNING: Only bash and zsh are supported.
Use of other shell would lead to erroneous results.


原因


这问题来得有点莫名奇妙, 从LOG上看是跟PS命令有关


function validate_current_shell() {
    local current_sh="$(ps -o command -p $$)"
    case "$current_sh" in
        *bash*)
            function check_type() { type -t "$1"; }
            ;;
        *zsh*)
            function check_type() { type "$1"; }
            enable_zsh_completion ;;
        *)
            echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
            ;;
    esac
}


导致这个问题, 是因为之前为了方便使用, 用alias重新定义了默认参数:

默认ps命令的输出结果:


$ ps
    PID TTY          TIME CMD
   7504 pts/1    00:00:01 bash
  49715 pts/1    00:00:00 ps


于是个修改了下ps命令:


alias ps='ps -la'


$ ps -la
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S   125    1395    1393  0  80   0 - 116589 -     tty1     00:00:00 Xorg
0 S   125    1624    1393  0  80   0 -  1324 -      tty1     00:00:00 dbus-run-sessio
0 S   125    1625    1624  0  80   0 -  1882 -      tty1     00:00:00 dbus-daemon
0 S   125    1626    1624  0  80   0 - 140163 -     tty1     00:00:00 gnome-session-b
0 S   125    1630       1  0  80   0 - 76386 -      tty1     00:00:00 at-spi-bus-laun
0 S   125    1635    1630  0  80   0 -  1778 -      tty1     00:00:00 dbus-daemon
0 S   125    1659    1626  0  80   0 - 991315 -     tty1     00:00:03 gnome-shell
0 S   125    1674    1659  0  80   0 - 78491 -      tty1     00:00:00 ibus-daemon
0 S   125    1677    1674  0  80   0 - 59900 -      tty1     00:00:00 ibus-dconf
0 S   125    1680       1  0  80   0 - 47781 -      tty1     00:00:00 ibus-x11
0 S   125    1683       1  0  80   0 - 59895 -      tty1     00:00:00 ibus-portal
0 S   125    1693       1  0  80   0 - 40709 -      tty1     00:00:00 at-spi2-registr
0 S   125    1697       1  0  80   0 - 59668 -      tty1     00:00:00 xdg-permission-
0 S   125    1712       1  0  80   0 - 684168 -     tty1     00:00:00 gjs
0 S   125    1719    1626  0  80   0 - 116964 -     tty1     00:00:00 gsd-sharing
0 S   125    1720    1626  0  80   0 - 84554 -      tty1     00:00:00 gsd-wacom
0 S   125    1723    1626  0  80   0 - 162019 -     tty1     00:00:00 gsd-color
0 S   125    1725    1674  0  80   0 - 41443 -      tty1     00:00:00 ibus-engine-sim
0 S   125    1728    1626  0  80   0 - 103080 -     tty1     00:00:00 gsd-keyboard
0 S   125    1734    1626  0  80   0 - 62823 -      tty1     00:00:00 gsd-print-notif
0 S   125    1735    1626  0  80   0 - 115044 -     tty1     00:00:00 gsd-rfkill
0 S   125    1744    1626  0  80   0 - 79560 -      tty1     00:00:00 gsd-smartcard
0 S   125    1751    1626  0  80   0 - 94174 -      tty1     00:00:00 gsd-datetime
0 S   125    1752    1626  0  80   0 - 223603 -     tty1     00:00:00 gsd-media-keys
0 S   125    1755    1626  0  80   0 - 59646 -      tty1     00:00:00 gsd-screensaver
0 S   125    1756    1626  0  80   0 - 80607 -      tty1     00:00:00 gsd-sound
0 S   125    1757    1626  0  80   0 - 78184 -      tty1     00:00:00 gsd-a11y-settin
0 S   125    1758    1626  0  80   0 - 78700 -      tty1     00:00:09 gsd-housekeepin
0 S   125    1765    1626  0  80   0 - 103342 -     tty1     00:00:01 gsd-power
0 S   125    1800       1  0  80   0 - 86316 -      tty1     00:00:00 gsd-printer
4 S  1000    1966    1964  3  80   0 - 178161 ep_pol tty2    00:57:12 Xorg
0 S  1000    1976    1964  0  80   0 - 47829 poll_s tty2     00:00:00 gnome-session-b
4 R  1000   49731    7504  0  80   0 -  3623 -      pts/1    00:00:00 ps


回到问题本身:

在envsetup.sh中


local current_sh="$(ps -o command -p $$)"


正常情况下, current_sh的值应该是:


$ ps -o command -p $$
COMMAND
bash


$$ Shell本身的PID(ProcessID)


而修改后的命令执行结果是:


$ ps -la -o command -p $$
error: conflicting format options
Usage:
 ps [options]
 Try 'ps --help <simple|list|output|threads|misc|all>'
  or 'ps --help <s|l|o|t|m|a>'
 for additional help text.
For more details see ps(1).


解决的办法很简单, 在PS前, 加上:unalias ps


function validate_current_shell() {
  #取消alais
    unalias ps
    local current_sh="$(ps -o command -p $$)"
    case "$current_sh" in
        *bash*)
            function check_type() { type -t "$1"; }
            ;;
        *zsh*)
            function check_type() { type "$1"; }
            enable_zsh_completion ;;
        *)
            echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
            ;;
    esac
}


当然, 最好能判断是否已经重定义了PS, 否则会出现:


$ . build/envsetup.sh 
bash: unalias: ps: not found


于是, 稍微修改下:


function validate_current_shell() {
  #取消alais
    if [[ $(type -t ps) == "alias" ]]; then
        unalias ps
    fi
    local current_sh="$(ps -o command -p $$)"
    case "$current_sh" in
        *bash*)
            function check_type() { type -t "$1"; }
            ;;
        *zsh*)
            function check_type() { type "$1"; }
            enable_zsh_completion ;;
        *)
            echo -e "WARNING: Only bash and zsh are supported.\nUse of other shell would lead to erroneous results."
            ;;
    esac
}


参考


alias

Shell脚本中0 、 0、0、?、! 、 !、!、、 、、*、KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲、@等的意义

shell command命令

-bash: unalias: ls: not found


相关文章
|
10天前
|
Linux Shell 开发工具
|
5天前
|
Linux
|
10天前
|
网络协议 安全 Linux
|
7天前
|
存储 运维 Linux
|
7天前
|
存储 JSON Linux
|
9天前
|
Oracle 关系型数据库 Linux
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
通过这一连串的步骤,可以专业且有效地在Linux下为Qt编译Oracle驱动库 `libqsqloci.so`,使得Qt应用能够通过OCI与Oracle数据库进行交互。这些步骤适用于具备一定Linux和Qt经验的开发者,并且能够为需要使用Qt开发数据库应用的专业人士提供指导。
19 1
讲解linux下的Qt如何编译oracle的驱动库libqsqloci.so
|
8天前
|
存储 安全 Ubuntu
Linux dump命令教程
绍了Linuxdump命令的功能,包括用于备份整个文件系统的全备份和增量备份,以及如何在不同Linux发行版中安装和使用dump命令。
45 16
|
4天前
|
Linux
《解析 Linux 命令:systemd-delta》
`systemd-delta`: 解析Linux服务配置差异。概览: 显示服务单元文件与默认配置的对比,助于配置问题排查与系统审计。特点: 清晰展示修改点,涵盖启动选项等。示例: `systemd-delta [--plain] &lt;service&gt;`. 注意: 理解默认配置,谨慎修改,定期检查。掌握此命令,深化系统服务配置洞察,优化Linux管理。#Linux #systemd-delta
|
4天前
|
运维 监控 Linux
深入了解 Linux 命令:systemd-cgtop
`systemd-cgtop`, 实时监控 Linux cgroup 资源使用的关键工具。它动态显示 CPU、内存、IO 等数据,支持实时更新与多维展示。常用参数 `-n` 限定行数,`-p` 按属性排序。结合 `grep` 可监控特定进程,如 `systemd-cgtop | grep 1234`。排序与限制输出: `systemd-cgtop -p memory -n 5`。最佳实践包括熟悉 cgroup 架构,整合其他监控工具,定期检查以预防资源瓶颈。掌握 `systemd-cgtop` 助力性能优化与管理。
|
4天前
|
存储 NoSQL Linux
《探索 Linux 命令:systemd-coredumpctl》
**《systemd-coredumpctl概览》** `systemd-coredumpctl`, Linux中管理&分析core dump的利器。集中管控systemd生成的转储,详述crash细节。用`--list`查看所有转储,`--info &lt;ID&gt;`深入单一转储。需注意权限、存储管理,配gdb深化分析。精通此命令,加速问题诊断。#LinuxTips #CoreDumpAnalysis