gpt4 book ai didi

linux - 需要帮助在 shell 脚本中查找 PID

转载 作者:太空宇宙 更新时间:2023-11-04 10:33:07 26 4
gpt4 key购买 nike

我是编写代码的新手。为了获取进程 ID,我得到了下面的代码,但我无法理解下面的命令到底在做什么,能否请任何人解释一下。

for PID in `ps -u ${instuser} -o pid,args |
grep "\-classpath :$path" | grep -v grep | sed 's/^ *//g' | cut -f1 -d' '`

特别是我无法理解他们为什么使用 pid、args 和 sed 命令。

你能帮我看看到底是什么吗?

最佳答案

ps 命令的 -o 选项控制输出如何显示,如手册所述:

-o
format User-defined format. format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify individual output columns.

sed 命令

sed 's/^ *//g'

修剪输出开头的空白。

关于linux - 需要帮助在 shell 脚本中查找 PID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38855439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com