Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I can verify that the connection is up:

$ netstat -tn | grep ""
tcp  0  0  ESTABLISHED

is there a way to check how long this tcp port connection was up (connected)?

(No, I don't have access to app logs)

share|improve this question

1 Answer 1

I haven’t seen netstat give that information. A combination of netstat and ps commands should be helpful.

  • Get pid of the socket with netstat.
$ sudo netstat -plan | grep ""

tcp        0      0       ESTABLISHED 2679/chromium-brows
  • Check process details with ps.
$ sudo ps -eo uid,pid,etime | grep 2679

1000  2679       44:31

The third value here is the total time the socket has been running.

To understand ps output better I am pasting the headings.

$  sudo ps -eo uid,pid,etime | head

0     1       52:37
share|improve this answer
if you do this on the sever side, this will give you how long the server was running. I am interested in how long the connection is up. Say the server started last month but the client connected only 2 days ago. In this case, on the server I get "one month" but I am looking for "2 days". –  hidralisk Mar 14 '13 at 23:12
This will in fact tell you how long the connection is up. I think only detailed logging will be able to tell how long the client was connected to the socket. This is definitely a lead. –  fspark Mar 15 '13 at 6:31

Your Answer


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.