gpt4 book ai didi

unix - lsof 的非零退出代码

转载 作者:行者123 更新时间:2023-12-01 02:10:30 27 4
gpt4 key购买 nike

我正在使用以下 lsof命令:

lsof -iTCP -a -sTCP:^LISTEN -a -p <pid>

如果有一些输出,此命令将返回退出代码 0但如果没有输出,退出代码是 1 .
echo $?

谁能解释为什么会这样?有没有办法避免它?

最佳答案

这是预期的行为:您只会得到 0如果发现了什么。

来自 man lsof :

DIAGNOSTICS

Errors are identified with messages on the standard error file.

Lsof returns a one (1) if any error was detected, including the failure to locate command names, file names, Internet addresses or files, login names, NFS files, PIDs, PGIDs, or UIDs it was asked to list. If the -V option is specified, lsof will indicate the search items it failed to list.

It returns a zero (0) if no errors were detected and if it was able to list some information about all the specified search arguments.

关于unix - lsof 的非零退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29841984/

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