如何显示 bash 会话的当前进程树? [英] How to display the current process tree of a bash session?

查看:105
本文介绍了如何显示 bash 会话的当前进程树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 bash 别名,为我提供从我正在使用的当前 bash 会话到 init 的进程树.

I would like to create a bash alias that gives me the process tree from the current bash session I am using, up to init.

用例是知道我是否使用过bashvi:shell 命令.

The use case is to know whether I have used bash or vi's :shell command.

我用的是MacOS X,听说过pstree,但好像只显示子进程,不显示init和当前进程的关系.

I am using MacOS X. I have heard about pstree, but it seems to only show children, not the relationship between init and the current process.

推荐答案

我相信通过一些谷歌搜索,您可以找到如何获取和下载 Mac 版 pstree.但是,您可以使用psppid 来制作穷人版.

I am sure with a a bit of google search, you can find how to get and download pstree for the Mac. However, you can do a poor man's version, using ps and ppid.

例如

ps -eo ppid,pid,cmd | awk '{p[$1]=p[$1]","$3}END{ for(i in p) print i, p[i]}'

这篇关于如何显示 bash 会话的当前进程树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆