Non zero exit code for lsof

情到浓时终转凉″ 提交于 2019-12-19 22:02:02

问题


I am using following lsof command:

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

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?


回答1:


This is the expected behaviour: you just get 0 if something was found.

From 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.



来源:https://stackoverflow.com/questions/29841984/non-zero-exit-code-for-lsof

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!