Launchd-owned processes unexpected behavior
Ok, so I have been struggling with this for a few days and I think I need an explanation of a few things before I go any further. I'm not sure it's possible to do what I'm trying, so before I pull my hair out, here is what I'm doing:
I have written a program in LiveCode that sits on our students' computers and kills games and other apps that they have downloaded while they are at school. We set this app up as a launchdaemon so that they can't kill it or disable it in any way. The app works great for the most part, but there is one piece of the puzzle I just can't get working properly.
The kids like to play minecraft, which runs as a standalone java application. I want to kill it when it is running. However, I want the kids to be able to use java web-apps.
So the root of the problem is that I only know of one way to differentiate between java running as a web-app within a browser or a standalone app, and that is to see if "java" is the active or "frontmost" (in appleScript parlance) process. So first, if there is a better way to make this determination, that could solve my problem.
My first solution was this:
osascript -e 'tell application "System Events" to return the name of every process whose frontmost is true'
or simply running that as an AppleScript within LiveCode. The problem is that sometimes I get an error when doing this. The error varies from compiler errors to syntax errors to execution errors depending on the configuration.
The main issue seems to be that if system events is not already running as a user-owned process, the command fails. I don't understand why. I assume it has something to do with running the app as a launchd process. Is there something fundamental about the way these processes work that I'm missing.
Since the AppleScript solution didn't work well, I tried having LiveCode launch a python script:
from AppKit import NSWorkspace activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName'] fo = open("/tmp/focus", "w") fo.write( activeAppName ) fo.close()
As you can see, I even had python write to a file so that LiveCode can check it. This way it doesn't even have to communicate directly with python. Again, however, it seems to get various errors or simply fail to execute when the app is running as a daemon, although it works fine when running it as a user-level application.
So that long-winded story is all to say that I think my problems have to do with how processes are spawned when their parent process is a child of launchd, or how commands from these processes are managed. Could this be? Or am I completely off-base?
EDIT: To clarify, I'm mostly seeking an explanation of caveats/special things to consider when running a process as a daemon. Any specific solutions to my problem would be extremely appreciated, but I'd be very happy for anything that would help enlighten me.
EDIT 2: How silly of me to to forget: This is for OS X 10.7.4/5
Last edited by nextyoyoma; 11-14-2012 at 07:07 PM.. Reason: clarify focus of question
|Thread Tools||Search this Thread|
|More UNIX and Linux Forum Topics You Might Find Helpful|
|Thread||Thread Starter||Forum||Replies||Last Post|
|unexpected behavior bash, set -o vi, history -a, and HISTFILE||gg48gg||UNIX for Advanced & Expert Users||8||10-05-2012 05:26 AM|
|iptables DNAT of outgoing destination port, unexpected behavior||cjh19460||IP Networking||0||05-22-2012 01:16 AM|
|help with counting processes, bizzare behavior||73rdUserID||Shell Programming and Scripting||4||12-14-2010 08:33 PM|
|Unexpected df behavior||Sapfeer||Solaris||9||03-17-2009 04:18 PM|
|interval in a launchd script||wessel||OS X (Apple)||1||03-15-2009 10:13 PM|