I am trying to get the pid of this command.
sudo -b tcpdump -i eth0 port 80 -w eth0.pcap
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
$!to get the pid of the last background process (which will be the sudo in this case), andps --ppidto find out about its children. So for example:If you’re doing this in a script, you might want to use a
sleep 1between thesudoandpsto ensure that the child gets started.Note that if you really must use the
-bflag to sudo, this won’t work, as that will cause sudo to do an extra fork and immediately exit, losing the connection between child and parent (the tcpdump command will get reparented to init), which means you’ll have no easy way of distinguishing the child from any other similar command.