Alex Rivera | Logout

How to get the pid of command running with sudo

Asked 2012-02-16T17:16:14.590
15

I am trying to get the pid of this command.

sudo -b tcpdump -i eth0 port 80 -w eth0.pcap
Edit
Report

1 Answer

4

for this purpose I will enter

sudo gvim &

ps aux | grep gvim

supplies me with the following output

root 11803 0.0 0.0 12064 2776 pts/3 T 12:17 0:00 sudo gvim

to grab only the pID i prefer to use awk

ps aux | awk '/gvim/ {print $2}'

which would return simply

11803

I could kill the program from awk as well by piping a kill command to bash

ps aux | awk '/gvim/ {print "sudo kill -9 "$2}' | bash

answered 2012-02-16T17:21:58.330

Your Answer