Kill process when PID is constantly changing

killprocess

When I issue

ps aux | grep mtp

I get

ubuntu-+ 15934 0.1 0.0 519848 7068 ? Sl 21:13 0:00
/usr/lib/gvfs/gvfsd-mtp –spawner :1.9 /org/gtk/gvfs/exec_spaw/20

So the PID in this case is 15934. But every new time this is run the PID is different. Is there any other way to kill a process other than by PID?

Best Answer

Probably there is a parent process which kills child processes and forks new children. You can use pstree to find the parent process:

pgrep mtp | xargs -i pstree -ps {}

Or alternatively you can use the ppid option of ps:

pgrep mtp | while read line; do ps -p $line -o ppid; done

Then you can kill the parent process

Related Question