Non zero exit code for lsof

后端 未结 1 2013
难免孤独
难免孤独 2021-01-18 19:04

I am using following lsof command:

lsof -iTCP -a -sTCP:^LISTEN -a -p 

If there is some output this command returns

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 19:10

    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.

    0 讨论(0)
提交回复
热议问题