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
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With