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
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
1032 1
二、Linux文本处理与文件操作核心命令
|
10月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
680 137
|
10月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1637 58
|
9月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1517 2
|
10月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
819 16
|
10月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
938 0
Linux内存问题排查命令详解
|
11月前
|
Linux 网络安全 开发工具
技术栈:这50条最常用的 Linux 命令你一定要会!
建议多在终端中实践,遇到不懂的命令就用 man 或 --help 了解详情!
2138 0
|
11月前
|
安全 Linux Shell
Linux系统中sudo命令的高效运用技巧。
用户可以通过sudo -l来列出自己目前可执行的命令列表,这有助于用户了解自己的权限范围。
415 0
|
11月前
|
监控 Linux Shell
linux命令
常用 Linux 命令汇总
|
Linux C++
每天一个linux命令(8):cp 命令
cp 命令是 Linux 中用于复制文件或目录的命令。它的名字来源于英文单词 copy。这个命令非常常用,特别是在需要备份文件或创建文件副本时。
736 0

热门文章

最新文章