0

This is my makefile:

start:
    emulator -avd Galaxy_Nexus_API_28 -writable-system &
    charles &
    
remount:
    adb -s emulator-5554 wait-for-device root 
    adb -s emulator-5554 wait-for-device shell mount -o rw,remount /
    adb -s emulator-5554 wait-for-device shell mount -o rw,remount /sys

stop:
    kill -9 $(ps -A | grep qemu-system-x86 | awk '{print $1}') &
    kill -9 $(ps -A | grep charles.jar | awk '{print $1}') &

test:
    ps -A | grep qemu-system-x86

Starting the android AVD and Charles works fine. Then when I run make stop --just-print I get this as output:

kill -9  &
kill -9  &

I guess this means the output of $(ps -A | grep qemu-system-x86 | awk '{print $1}') is empty. This is weird because of two reasons:

First because when I run make test I get the following (correct) output:

ps -A | grep qemu-system-x86
  64434 pts/0    00:00:59 qemu-system-x86

Second, because running echo $(ps -A | grep qemu-system-x86 | awk '{print $1}') in the terminal nicely prints the correct pid of the process. So the ps | grep command works in the makefile, but the awk print addition only works in the terminal. How can this be? And how do I fix it?

For now I'm going to stick to using killall -9 java upon calling make stop but this is of course not the nicest way to handle things.

Anteino
  • 1,044
  • 7
  • 28

1 Answers1

0

Suggesting to try simplify stop target with pkill commands. Like this:

stop:
    pkill -9 -f qemu-system-x86
    pkill -9 -f charles.jar

This solution also solve the problem of killing the grep or awk command containing the target pattern instead of killing the target process command.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Dudi Boy
  • 4,551
  • 1
  • 15
  • 30