1

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?

edwinksl
  • 23,569
  • 16
  • 74
  • 100
Bachalo
  • 753
  • 2
  • 10
  • 27
  • 1
    Check out `pkill` (to read its manpage, type `man pkill`), it allows you to kill processes by their filename and other attributes. – Byte Commander Dec 28 '16 at 21:53
  • `killall` is also worth a try... eg. `killall mtp`. – Baard Kopperud Dec 28 '16 at 22:23
  • 5
    See [How to kill the process using the name of the program instead of PID?](https://askubuntu.com/questions/396684/how-to-kill-the-process-using-the-name-of-the-program-instead-of-pid) For deciding between `killall` and `kill`, [What's the difference between 'killall' and 'pkill'?](https://askubuntu.com/questions/27501/whats-the-difference-between-killall-and-pkill) may be of interest. – Eliah Kagan Dec 28 '16 at 23:45

2 Answers2

2

You can use ps to find the PID of the process, then pass that to kill:

kill $(ps -C /usr/lib/gvfs/gvfsd-mtp -o pid=)

The -C flag specifies a command name to search for in the list of processes, and the -o pid= option means ps will print only the PID. The result is passed as the only argument to kill.

Travis G.
  • 1,837
  • 1
  • 13
  • 15
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 the supplied answer above I assume will also work!

muru
  • 193,181
  • 53
  • 473
  • 722
Bachalo
  • 753
  • 2
  • 10
  • 27