Linux命令 --- ps/pstack/pstree

pstack
pstack pid
显示某个进程的栈跟踪,必须在对应的用户组或root下操作。

[wuchunlai@s1 ~]$ sudo -u work pstack $(pgrep cc_engine)
Thread 3 (Thread 0x7fb3467ff700 (LWP 6130)):
#0  0x000000370cae5d03 in epoll_wait () from /lib64/libc.so.6
#1  0x000000000042af06 in cc_loop_run ()
#2  0x0000000000418019 in cc_single_send_start ()
#3  0x000000370ce077f1 in start_thread () from /lib64/libpthread.so.0
#4  0x000000370cae570d in clone () from /lib64/libc.so.6
Thread 2 (Thread 0x7fb345dfe700 (LWP 6131)):
#0  0x000000370caaab9d in nanosleep () from /lib64/libc.so.6
#1  0x000000370caaaa10 in sleep () from /lib64/libc.so.6
#2  0x00000000004083b1 in cc_collect_log ()
#3  0x000000370ce077f1 in start_thread () from /lib64/libpthread.so.0
#4  0x000000370cae570d in clone () from /lib64/libc.so.6
Thread 1 (Thread 0x7fb346ca2840 (LWP 6128)):
#0  0x000000370ca32c34 in sigsuspend () from /lib64/libc.so.6
#1  0x0000000000433d42 in cc_sig_wait ()
#2  0x000000000040600c in cc_client_process ()
#3  0x0000000000405be2 in cc_run ()
#4  0x0000000000405c2a in main ()

pstree
pstree
以树状结构显示所有进程的关系,只显示进程名字,并且相同进程合并。

pstree -p
显示所有的进程,并添加进程号

pstree -p
显示进程PID为的进程以及子孙进程,如果有-p则显示每个进程的PID。

pstree -a
相同名称进程不合并,并且会显示命令行参数

pstree
可以跟一个用户参数,表示显示哪个用户的进程列表。

因为pstree输出的信息可能比较多,所以最好与more/less配合使用。

[wuchunlai@s1 ~]$ pstree -p $(pgrep cc_engine)
cc_engine(6128)─┬─{cc_engine}(6130)
                └─{cc_engine}(6131)

ps
-A/e 列出所有的进程
-a 显示一个终端的所有进程,除了会话引线
-d 显示所有进程,省略所有回话引线
-x 显示没有控制终端的进程,同时显示各个命令的具体路径。dx不可合用。
-w 显示加宽可以显示较多的资讯
-f 列出全部选项
-o 用户自定义格式 pid/uname/pcpu/pmem/rsz/comm

-p pid 显示pid使用的cpu时间
-u uid/user 选择用户
-g gid/group 选择组
-C name 选择进程
–sort=-pcpu,+pmem 根据后加选项进行排序,-表示降序+表示升序

ps aux == ps -ef 列出所有进程
ps -fC … == ps -ef | grep …

install -d -m0755 /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages ipkg-build -c -o 0 -g 0 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages Packaged contents of /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-cn913x/gdb into /home/felix/mydisk/enterprise_gateway/bin/cn913x-cn25g-vpp_v1/packages/gdb_8.1-1_cn913x.ipk rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb mkdir -p /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb install -d -m0755 /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ install -m0755 /home/felix/mydisk/enterprise_gateway/build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-8.1/ipkg-install/usr/bin/gdb /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/bin/ install -m0755 ./files/usr/sbin/pstack /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/usr/sbin/ SHELL= /home/felix/mydisk/enterprise_gateway/staging_dir/host/bin/flock /home/felix/mydisk/enterprise_gateway/tmp/.root-copy.flock -c 'cp -fpR /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb/. /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/' rm -rf /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/tmp-gdb touch /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/root-cn913x/stamp/.gdb_installed if [ -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean ]; then rm -f /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install.clean; fi; echo "gdb" >> /home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/pkginfo/gdb.default.install WARNING: skipping gdbserver -- package not selected make[3]: Leaving directory '/home/felix/mydisk/enterprise_gateway/package/devel/gdb' make[2]: Leaving directory '/home/felix/mydisk/enterprise_gateway' package/Makefile:190: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile] Error 2 make[1]: Leaving directory '/home/felix/mydisk/enterprise_gateway' /home/felix/mydisk/enterprise_gateway/include/toplevel.mk:171: recipe for target 'world' failed make: *** [world] Error 2
最新发布
07-29
<think>我们面对的是一个在编译企业级网关(enterprise_gateway)时,在gdb包编译阶段出现的错误。错误信息显示: ``` package/Makefile:190: recipe for target '/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile' failed make[1]: *** [/home/felix/mydisk/enterprise_gateway/staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/stamp/.package_compile] Error 2 ... make: *** [world] Error 2 ``` ### 错误分析 1. **错误本质**:`Error 2`通常表示编译过程中遇到了致命错误,导致编译终止。具体原因需要查看更详细的编译日志。 2. **错误位置**:错误发生在`package/Makefile`的第190行,目标为`stamp/.package_compile`,这通常意味着在编译某个包(这里是gdb)时失败。 3. **环境信息**:目标平台为`aarch64-marvell-linux-gnu`,这是一个ARM64架构的交叉编译环境。 ### 可能原因及解决方案 #### 1. 查看详细编译日志 由于错误信息不够具体,我们首先需要获取详细的错误日志。在编译时使用`V=s`或`V=sc`选项可以输出详细日志: ```bash make V=s 2>&1 | tee build.log ``` 然后搜索`gdb`相关的错误信息,特别是失败前的最后几条错误和警告。 #### 2. 常见原因及对策 ##### a) 依赖问题 - **缺失依赖库**:gdb编译可能依赖一些库(如zlib、expat、ncurses等),在交叉编译环境下,需要确保这些库已正确编译并安装在staging目录中。 - **解决方案**:检查gdb的配置选项,确认依赖库的路径是否正确。可以在`package/gdb/Makefile`中检查配置选项,确保指定了交叉编译的依赖库路径。 ##### b) 工具链问题 - **工具链未正确设置**:交叉编译工具链(如`aarch64-marvell-linux-gnu-gcc`)可能未正确设置或存在版本不兼容。 - **解决方案**:手动检查工具链是否可用: ```bash # 进入工具链目录 cd staging_dir/toolchain-aarch64-marvell-linux-gnu-cn25g-vpp_v1/bin ./aarch64-marvell-linux-gnu-gcc --version ``` 如果工具链不可用,可能需要重新安装或修复工具链。 ##### c) 配置选项错误 - **gdb配置选项不兼容目标平台**:gdb的配置选项可能包含与目标平台不兼容的选项。 - **解决方案**:在`package/gdb/Makefile`中,检查`CONFIGURE_ARGS`和`CONFIGURE_VARS`,确保它们适合ARM64架构。例如: ```makefile CONFIGURE_ARGS += \ --target=aarch64-marvell-linux-gnu \ --host=aarch64-marvell-linux-gnu \ --prefix=/usr ``` ##### d) 代码或补丁问题 - **gdb源码或补丁问题**:可能gdb的某个版本在目标平台上有已知问题,或者应用的补丁不适用。 - **解决方案**:尝试更新gdb到更新版本,或回退到已知稳定的版本。检查OpenWrt的gdb包是否有更新或补丁。 #### 3. 临时解决编译错误 如果错误是由编译器警告被视为错误导致的(类似引用[3]中的情况),可以尝试关闭`-Werror`编译选项: ```makefile # 在package/gdb/Makefile中修改编译选项 TARGET_CFLAGS += -Wno-error ``` #### 4. 并行编译问题 尝试使用单线程编译以排除并行编译导致的问题: ```bash make -j1 V=s ``` ### 调试步骤 1. **进入gdb编译目录**: ```bash cd build_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/gdb-<version> ``` 2. **手动配置和编译**: ```bash # 清理之前的状态 make clean # 手动配置 ./configure --target=aarch64-marvell-linux-gnu --host=aarch64-marvell-linux-gnu --prefix=/usr # 手动编译,查看具体错误 make V=1 ``` ### 相关问题 1. 如何为ARM64架构交叉编译gdb?[^1] 2. 如何解决OpenWrt构建中包编译失败的问题?[^2] 3. 在交叉编译环境中,如何正确处理依赖库?[^3] 4. 如何调试Makefile中的`Error 2`?[^4]</think>### 解决企业网关构建中GDB包编译失败的问题 根据错误信息和嵌入式编译环境特点,以下是系统化的解决方案: #### 核心问题分析 1. **错误本质**:`Error 2`表示GDB包在交叉编译过程中遇到致命错误 2. **关键线索**: - 目标平台:`aarch64-marvell-linux-gnu-cn25g-vpp_v1` - 失败位置:`package/Makefile:190`的`.package_compile`目标 - 深层错误:实际编译日志可能被隐藏(需开启详细输出) #### 解决方案 ##### 1. 获取详细错误日志(关键步骤) ```bash # 重新编译并捕获完整日志 make -j1 V=sc 2>&1 | tee build.log ``` - `-j1`:禁用并行编译,避免日志交错 - `V=sc`:显示完整命令和检查点信息 - 在日志中搜索关键词:`gdb`、`aarch64`、`marvell` ##### 2. 交叉编译工具链验证 ```bash # 检查工具链配置 echo $ARCH echo $CROSS_COMPILE ls -l staging_dir/toolchain-aarch64-marvell-linux-gnu-cn25g-vpp_v1/bin # 测试工具链功能 staging_dir/toolchain-aarch64-marvell-linux-gnu-cn25g-vpp_v1/bin/aarch64-marvell-linux-gnu-gcc --version ``` - 若工具链缺失,需重新生成:`make toolchain/install V=s` ##### 3. GDB包特定修复 在`package/gdb/Makefile`中添加ARM64补丁: ```makefile # 添加补丁解决常见交叉编译问题 define Package/gdb/patches $(if $(CONFIG_aarch64), \ $(PATCH_DIR)/100-gdb-aarch64-musl.patch \ $(PATCH_DIR)/101-gdb-py-configure-path.patch) endef ``` 常见补丁获取:[OpenWrt GDB补丁集](https://git.openwrt.org/?p=packages.git;a=tree;f=devel/gdb/patches) ##### 4. 依赖库检查 ```bash # 验证关键依赖 grep -rn "DEPENDS" package/gdb/Makefile ls staging_dir/target-aarch64-marvell-linux-gnu-cn25g-vpp_v1/usr/lib/libz.so* ``` 常见缺失依赖: - **zlib**:`opkg install zlib-dev` - **ncurses**:`make package/ncurses/compile V=s` - **expat**:`make package/expat/compile V=s` ##### 5. 配置优化 在`.config`文件中添加: ```config CONFIG_GDB_DEBUG=y CONFIG_GDB_PYTHON=n # 临时禁用Python扩展 CONFIG_GDB_TUI=y # 启用文本界面支持 ``` #### 调试流程图 ```mermaid graph TD A[编译失败 Error 2] --> B{获取详细日志} B --> C[工具链验证] B --> D[依赖库检查] C --> E[工具链重装] D --> F[缺失库编译] E --> G[应用GDB补丁] F --> G G --> H[单线程重编译] H --> I{成功?} I -->|否| J[分析具体错误] I -->|是| K[完成] ``` #### 典型错误修复示例 **问题**:`unrecognized command-line option '-maarch64'` **修复**:在`package/gdb/Makefile`中移除冲突标志: ```makefile TARGET_CFLAGS := $(filter-out -maarch64,$(TARGET_CFLAGS)) ``` **问题**:`fatal error: expat.h: No such file or directory` **修复**:安装依赖并重设包含路径: ```bash make package/expat/install export C_INCLUDE_PATH=$PWD/staging_dir/target-aarch64-*/usr/include ``` ### 相关问题 1. 如何为ARM64架构交叉编译GDB调试器?[^1] 2. OpenWrt构建系统中`V=s`和`V=sc`参数有什么区别?[^2] 3. 如何为嵌入式系统创建自定义GDB补丁?[^3] 4. Marvell CN25G平台编译需要哪些特殊配置?[^4] 5. 如何解决交叉编译中的"头文件不存在"错误?[^1]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值