Sometimes (not too often at all) when I type "netstat", it takes over 5 seconds to return. While other times is instantaneous.

I have been observing this for weeks on my server (CentOS 6.4), but I don't understand why!?

Can anyone give an explanation?


Solution 1:

It's all DNS resolution. If the DNS server is slow, it delays netstat. Pass -n to netstat when you invoke it to skip resolution and it'll often return immediately.

The other cause of the delay is if you use the -p (-b in Windows) to return the process owner since some processes don't like to be queried if you're not root/Administrator.