8

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?

  • Different PID → different process. – phk Dec 28 '16 at 21:31
  • 3
    If the PID is constantly changing then the process is constantly exiting and a new process with the same name is starting. So you probably want to go after the parent process, the one that is starting the children. Look at ps -ely | awk 'NR==1||/mtp/' and look at the PPID column – icarus Dec 28 '16 at 22:00
  • 1
    A better approach would be to understand what is actually going on, and fix that instead. Find out why the MTP mount isn't working, by checking logs and so forth, and fix it so that it actually works. Find out why GVFS even attempts the MTP mount, and stop it from needing it. Find out where MTP automount is happening, and turn it off. Find out why GVFS is needed at all, and stop that being so. As opposed to killing processes willy-nilly without understanding, and breaking one's GNOME desktop applications as a consequence. – JdeBP Dec 29 '16 at 7:08
8

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

0

You can use pkill mtp, or kill -9 pidof mtp

Please notice that if there are several mtp processes, both these commands will kill all the mtp processes in the system.

Rami Rosen

  • 5
    This or killall mtp will kill mtp's, however, possibly there is another process which constantly forks new mtp processes as children. Without killing, this is of no use. – Serhat Cevikel Dec 28 '16 at 22:07
0

I issued

ps aux | grep mtp

which gave me a few mtp related processes and compared with the camera mounted and unmounted to get the specific process

and then

pkill -9 gvfsd-mtp

does the trick.

But I assume the above answer will work as well:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.