How to deteck background Processes

1,038 views
Skip to first unread message

Nuno Mendes

unread,
Aug 14, 2012, 7:23:30 AM8/14/12
to tas...@googlegroups.com
Hey, so I wanted to include a notification to stay active and interact with it, while a app is open, but the problem is that the App uses a backend app, so the main app is "closed" but the backend app is there to call it again fast. On Tasker I can't find the way to get to that backend app, since it only shows me the "Main" installed app. So everytime i press Home, or go back(without clicking the exit button on the APP), the notification closes...

Anyway to get the backend app? The app is Unified Remote if it helps.

Nuno Mendes

unread,
Aug 14, 2012, 7:26:14 AM8/14/12
to tas...@googlegroups.com
To be more clear my profile is like this:

Context: App Load: Unified Remote
Task: Notification, Permanent, Title: Unified Remote, text: ON.
Exit Task: Notication Cancel the name above

Then i got another context:
Notification Click: Notified Remote,
Task: App Load: Unified Remote

Matt R

unread,
Aug 14, 2012, 1:05:00 PM8/14/12
to tas...@googlegroups.com
There's no way to detect if an app is in the background with built-in Tasker functions.  You can get possibly get some of that info with shell commands run through Tasker, but I don't know the exact commands.
 
Matt

Nuno Mendes

unread,
Aug 14, 2012, 1:30:59 PM8/14/12
to tas...@googlegroups.com
:( Ok :x

Have no idea too :P

DMagician

unread,
Aug 15, 2012, 2:41:12 AM8/15/12
to tas...@googlegroups.com
Hello.

Shell commands for running process:

while it is running, ps command will give you all current running processes.

if you know the process name (even partial),
you can execute 

# Shell script file begin
#!/bin/sh
PID=`ps -o pid | grep "THE PROCESS NAME"`
echo $PID
# Shell script file end

and this script will print the pid of the given process

OR you can check for return value (e.g. like DOS errorlevel if you know of).
something like:
ps | grep -i tasker & if [ "$?" == "0" ] then; echo "OK"; else echo "ERROR"

Hope this helps someone...

DMagician

unread,
Aug 15, 2012, 2:44:31 AM8/15/12
to tas...@googlegroups.com
I've forgot, after the lass part [ echo "ERROR"], there should be ; fi
E.g.

ps | grep -i tasker & if [ "$?" == "0" ] then; echo "OK"; else echo "ERROR"; fi

Adamx

unread,
Aug 15, 2012, 10:04:38 AM8/15/12
to tas...@googlegroups.com
I did some searching, and there's no facility in Android/Linux that seems capable of doing this without setting up some kind of loop, whether it's running a watch command, a shell script loop, or a loop in Tasker.

I was hoping there might be something like doing a 'tail -f' command on some kernel output, but that doesn't seem to exist.

Matt R

unread,
Aug 15, 2012, 11:56:59 AM8/15/12
to tas...@googlegroups.com
So I looked into this more because I was curious.  An alternative to DMagician's is to use oom_adj values.  The shell command:
 
cat /proc/$(pidof package.name)/oom_adj
 
will output the oom_adj value of the process, which should be 0 for what's running in the foreground, 2 for what's running in the background, and higher than 2 if it's cached but not running (or will error if the process isn't even cached).  This benefit of doing this is you can test if a process is running in the background, as opposed to just being cached in memory.  I believe the ps command will output even the cached processes, which you may or may not care about.
 
Matt

GermainZ

unread,
Mar 4, 2013, 2:34:34 PM3/4/13
to tas...@googlegroups.com
It's worth noting that scripts and apps that tweak oom values (e.g. V6 Supercharger, RAM Optimizer, etc) will, well, tweak the oom values. That means a task that works fine for you might not work on another device as expected unless you make sure the same oom_adj values are used for e.g. backgrounds apps.

On Monday, March 4, 2013 6:06:13 PM UTC+2, Dale Offret Jr. wrote:
Matt -- Add to your post.  I found the oom_adj values are -17 to +15.  Is is a value used by app killers to free up memory.  I looked for my process.  It has a value of -16.  It runs in the foreground with a notification bar icon.  So I will test for that.  Thanks for the hint and pointer in the right direction.
 
Some short reference sites on oom_adj and task killing in Android:
Reply all
Reply to author
Forward
0 new messages