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?
This is the expected behaviour: you just get
0
if something was found.From
man lsof
: