lsof -i not displaying processes with opened sockets












1















I wrote a script based on lsof to monitor the socket in use for each process of my particular application (one socket per process). When I specify the -i option to limit the list of opened files to sockets, some processes go missing.



Let pid_list be a constant and properly formatted comma separated list of 136 processes. Why is the result sometimes less than 136?



$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
135
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
134
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
136


The problem can be reproduced with as few as 1 pid.



$ clear ; lsof -p 5404  -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
### OOPS!!!
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0


Processes run without interruption. Each process has one socket that is either in LISTEN or ESTABLISHED state. Sockets are IPv4. This is on RHEL 5.11 with lsof 4.78.



Omitting lsof option -i will always output the correct number of processes. But that output is unusable for my purposes as I need the ip and port numbers of all processes.



Processes omitted by lsof appear to be random. They're never the same.



I suspect lsof is sensitive to something, but what?



EDIT 2016-07-26



I tried using netstat as a workaround and I encountered the same issue. The problem could be specific to my application, or some combination of what my app does and operating system constraints. Something prevents lsof/netstat from reporting properly.










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

    – Gilles
    May 9 '16 at 22:08
















1















I wrote a script based on lsof to monitor the socket in use for each process of my particular application (one socket per process). When I specify the -i option to limit the list of opened files to sockets, some processes go missing.



Let pid_list be a constant and properly formatted comma separated list of 136 processes. Why is the result sometimes less than 136?



$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
135
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
134
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
136


The problem can be reproduced with as few as 1 pid.



$ clear ; lsof -p 5404  -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
### OOPS!!!
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0


Processes run without interruption. Each process has one socket that is either in LISTEN or ESTABLISHED state. Sockets are IPv4. This is on RHEL 5.11 with lsof 4.78.



Omitting lsof option -i will always output the correct number of processes. But that output is unusable for my purposes as I need the ip and port numbers of all processes.



Processes omitted by lsof appear to be random. They're never the same.



I suspect lsof is sensitive to something, but what?



EDIT 2016-07-26



I tried using netstat as a workaround and I encountered the same issue. The problem could be specific to my application, or some combination of what my app does and operating system constraints. Something prevents lsof/netstat from reporting properly.










share|improve this question
















bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

    – Gilles
    May 9 '16 at 22:08














1












1








1








I wrote a script based on lsof to monitor the socket in use for each process of my particular application (one socket per process). When I specify the -i option to limit the list of opened files to sockets, some processes go missing.



Let pid_list be a constant and properly formatted comma separated list of 136 processes. Why is the result sometimes less than 136?



$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
135
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
134
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
136


The problem can be reproduced with as few as 1 pid.



$ clear ; lsof -p 5404  -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
### OOPS!!!
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0


Processes run without interruption. Each process has one socket that is either in LISTEN or ESTABLISHED state. Sockets are IPv4. This is on RHEL 5.11 with lsof 4.78.



Omitting lsof option -i will always output the correct number of processes. But that output is unusable for my purposes as I need the ip and port numbers of all processes.



Processes omitted by lsof appear to be random. They're never the same.



I suspect lsof is sensitive to something, but what?



EDIT 2016-07-26



I tried using netstat as a workaround and I encountered the same issue. The problem could be specific to my application, or some combination of what my app does and operating system constraints. Something prevents lsof/netstat from reporting properly.










share|improve this question
















I wrote a script based on lsof to monitor the socket in use for each process of my particular application (one socket per process). When I specify the -i option to limit the list of opened files to sockets, some processes go missing.



Let pid_list be a constant and properly formatted comma separated list of 136 processes. Why is the result sometimes less than 136?



$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
135
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
134
ptxrxts5:/rxnet/hermes/envp/current
$ lsof -p $pid_list -a -i -nP -FpcnT | grep ^p | wc -l
136


The problem can be reproduced with as few as 1 pid.



$ clear ; lsof -p 5404  -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
### OOPS!!!
$ clear ; lsof -p 5404 -a -i -nP -FpcnT
p5404
cprocess
nsource:port->dest:port
TST=ESTABLISHED
TQR=0
TQS=0


Processes run without interruption. Each process has one socket that is either in LISTEN or ESTABLISHED state. Sockets are IPv4. This is on RHEL 5.11 with lsof 4.78.



Omitting lsof option -i will always output the correct number of processes. But that output is unusable for my purposes as I need the ip and port numbers of all processes.



Processes omitted by lsof appear to be random. They're never the same.



I suspect lsof is sensitive to something, but what?



EDIT 2016-07-26



I tried using netstat as a workaround and I encountered the same issue. The problem could be specific to my application, or some combination of what my app does and operating system constraints. Something prevents lsof/netstat from reporting properly.







linux lsof






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 26 '16 at 15:18







Philippe A.

















asked May 9 '16 at 21:37









Philippe A.Philippe A.

1165




1165





bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 5 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

    – Gilles
    May 9 '16 at 22:08














  • 1





    Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

    – Gilles
    May 9 '16 at 22:08








1




1





Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

– Gilles
May 9 '16 at 22:08





Are they IPv4 sockets? IPv6? Show us the lsof output for the processes that are getting omitted. Are you sure that they do have an IP socket open at the time lsof looks at them?

– Gilles
May 9 '16 at 22:08










1 Answer
1






active

oldest

votes


















0














Trying using with sudo privilege. Some processes won't show if the command is not executed with sudo privilege.






share|improve this answer
























  • My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

    – Philippe A.
    Jul 26 '16 at 18:02











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f282123%2flsof-i-not-displaying-processes-with-opened-sockets%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Trying using with sudo privilege. Some processes won't show if the command is not executed with sudo privilege.






share|improve this answer
























  • My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

    – Philippe A.
    Jul 26 '16 at 18:02
















0














Trying using with sudo privilege. Some processes won't show if the command is not executed with sudo privilege.






share|improve this answer
























  • My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

    – Philippe A.
    Jul 26 '16 at 18:02














0












0








0







Trying using with sudo privilege. Some processes won't show if the command is not executed with sudo privilege.






share|improve this answer













Trying using with sudo privilege. Some processes won't show if the command is not executed with sudo privilege.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jul 26 '16 at 17:32









BidyutBidyut

1317




1317













  • My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

    – Philippe A.
    Jul 26 '16 at 18:02



















  • My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

    – Philippe A.
    Jul 26 '16 at 18:02

















My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

– Philippe A.
Jul 26 '16 at 18:02





My context does not allow using root. Besides, root shouldn't be necessary as I am inspecting processes that I own.

– Philippe A.
Jul 26 '16 at 18:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f282123%2flsof-i-not-displaying-processes-with-opened-sockets%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

CARDNET

Boot-repair Failure: Unable to locate package grub-common:i386

Aws NAT - Aws IGW- Aws router