Wednesday, June 12, 2013

Killing zombies on a BlackBerry 10 device from CLI

I'm porting a SDL based game to BlackBerry 10. The app does not yet handle the swipe-up + exit gesture properly and gets stuck in the background.

I don't know exactly what happens but the app is still running and I can't restart it and the app window  is also hidden from the task list view. Restarting fixes it obviously, but there must be a more sane way to kill it.

So what to do? The obvious way, ssh into it and running something like, say:

ps | grep appname
kill -9 

But nooo.. the paranoid people at BlackBerry has removed the QNX ps command from the BB10 Core OS.

$ ps
sh: ps: cannot execute - No such file or directory
$ which ps
which: no ps in /usr/bin:/bin:/usr/sbin:/sbin

So now what? I did ask on the forums for some help, got a link to a application for slaying zombies, but that did seem a bit overkill for a simple thing like this, so a quick dive into the code slayer showed that QNX has a /proc filesystem listing all the processes. Obviously to make it a PITA the permissions are all dr-x--x--x

But here, a poor mans ps command:

for i in /proc/*/cmdline ; do echo $i; cat $i; done

Find the line that prints out the cmdline for your app and get the pid from the line above, kill -9 it and there you have it!