1

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • 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. – Sven Apr 03 '14 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 03 '14 at 13:07
  • @VictorMezrin great, I've added it as an answer – faker Apr 03 '14 at 14:49

1 Answers1

3

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.

faker
  • 211