Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find a process id using netstat in combination with ps

Tags:

linux

bash

I want to find the process id using netstat and see how long this process has been running by using ps. I currently have two separate commands to do this. How do I do it with one command?

netstat -anp | grep http | grep ESTABLISHED | awk {'print $7}' | awk -F '/' {'print $1'}

and:

ps -eo pid,uid,ruser,etime | grep someuser
like image 360
ibash Avatar asked Jan 18 '13 11:01

ibash


People also ask

Does netstat show PID?

The Netstat.exe command has a switch, that can display the process identifier (PID) that is associated with each connection to identify port conflicts. This information can be used to determine which process (program) listens on a given port.

How do you find the PID of a process?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

Which is PID in ps command?

The four columns are labeled PID , TTY , TIME , and CMD . PID - The process ID. Usually, when running the ps command, the most important information the user is looking for is the process PID. Knowing the PID allows you to kill a malfunctioning process . TTY - The name of the controlling terminal for the process.


1 Answers

for i in `netstat -anp | grep http | grep ESTABLISHED | awk {'print $7}' | awk -F '/' {'print $1'} | uniq` ; do ps -eo pid,uid,ruser,etime | grep $i ; done
like image 129
Suku Avatar answered Oct 16 '22 22:10

Suku