lsof的非零退出代码 [英] Non zero exit code for lsof
问题描述
我正在使用以下lsof
命令:
lsof -iTCP -a -sTCP:^LISTEN -a -p <pid>
如果有输出,此命令将返回退出代码0
,但如果没有输出,则退出代码为1
.
If there is some output this command returns an exit code of 0
but if there is no output the exit code is 1
.
echo $?
任何人都可以解释为什么会这样吗?有办法避免吗?
Can anyone explain why is this happening? Is there a way to avoid it?
推荐答案
这是预期的行为:如果找到了内容,您只会得到0
.
This is the expected behaviour: you just get 0
if something was found.
来自man lsof
:
诊断
使用标准错误文件上的消息标识错误.
Errors are identified with messages on the standard error file.
Lsof将返回一(1),包括 找不到命令名,文件名,Internet地址 或询问的文件,登录名,NFS文件,PID,PGID或UID 列出.如果指定了-V选项,lsof将指示搜索 未能列出的项目.
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.
如果未检测到错误并且能够列出有关所有指定搜索参数的某些信息,则返回零(0).
这篇关于lsof的非零退出代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!