Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to write lsof output for several network ports into bash variable.

Simple $(lsof -i :5555) doesn't work - lsof waits for quit command (Ctrl-C) every time I call it.

I can't figure out how to solve my task. Please, help

share|improve this question

migrated from serverfault.com Apr 4 at 15:27

This question came from our site for professional system and network administrators.

1  
More details, e.g. what OS? What happens if you run lsof as a single command? It works here on Ubuntu 12.04 and CentOS 6.5. –  SvW Apr 3 at 13:03
1  
Usually when lsof takes a long time to complete it is because DNS resolution takes too long. Could that be it? Try adding -n –  faker Apr 3 at 13:07
    
Yes, with -n it works. Thank you –  Victor Mezrin Apr 3 at 13:21
    
@VictorMezrin great, I've added it as an answer –  faker Apr 3 at 14:49

1 Answer 1

up vote 3 down vote accepted

A long running lsof process usually means that DNS resolution is timing out or not working correctly which is delaying the output of it.
You can disable DNS resolution by adding the -n option.

Of course you might want to check out why DNS resolution is taking too long on your server as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.