1

I would like to find a specific target's pid and kill this process.

Then, i made a shell:

#!/bin/bash
#

func(){

while true; do 

adb shell ps | grep my-target-process | awk '{print $2}' | xargs adb shell kill 

sleep 1

done
}

But, i always get errors like below :

usage:  kill [-s signame | -signum | -signame] { job | pid | pgrp } ...
    kill -l [exit_status ...]

Is there anything wrong? Thanks.

Sweet
  • 13
  • 3

1 Answers1

1

I will add an explanation the logic I suggested in the comments section. The reason why

| xargs -I{} adb shell kill "{}" 

works is, with the -I{} flag in xargs, the {} becomes a placeholder for the output returned from the previous command, i.e. the process-id is now present in {} and can be passed as an argument/input to your kill command.

(also) As an alternative, if your Android version supports pidof command, which returns the process-id pid directly, you can do

adb shell pidof -s "my-target-process" | xargs -I{} kill "{}"
Inian
  • 80,270
  • 14
  • 142
  • 161
  • @lnian sorry for late, i was in a global trip previously, thanks very much for your clarification – Sweet Dec 26 '16 at 08:33