Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Launchd-owned processes unexpected behavior Post 302731289 by nextyoyoma on Wednesday 14th of November 2012 05:33:05 PM
Old 11-14-2012
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:
Code:
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:
Code:
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
 

10 More Discussions You Might Find Interesting

1. OS X (Apple)

interval in a launchd script

Hi, i'm planning a to automate my backup with a rsync user deamon in my launchd and let that run every 2 hours. my server contains a lot of video data which can expand rapidly , up to 1TB, in an interval of 2 hours. now i'm wondering what will happen when a rsync is running longer then the... (1 Reply)
Discussion started by: wessel
1 Replies

2. Solaris

Unexpected df behavior

Hi, I have Sun SPARC Enterprise T5140 with two 2,5" 15rpm 146GB SAS HDD. In friday there were a lot of errors with fs on them. After reconfiguring all seemed to be fine but today I get the following strange behavior of df -kh command and troubles with files, I written on first disk in friday.... (9 Replies)
Discussion started by: Sapfeer
9 Replies

3. OS X (Apple)

[launchd] Creating a basic firewall

Hi, I'm trying to use launchd to detect whether certain ports are opened and if they are then to take some appropriate action, e.g. close the port or, worst case scenario, down the whole net connection. Apparently, force closing a port is not possible without killing the offending binary so... (3 Replies)
Discussion started by: ASGR
3 Replies

4. Shell Programming and Scripting

help with counting processes, bizzare behavior

I have a ksh script (dtksh Version M-12/28/93d on Solaris 10) that is run daily by cron and sometime hangs forever. I need to detect if there is an old copy hung before I start the new run, and if so send an email and exit the script. Here is part of the code: #!/usr/dt/bin/dtksh... (4 Replies)
Discussion started by: 73rdUserID
4 Replies

5. UNIX for Advanced & Expert Users

kill process owned by another user

How can I kill a process owned by user1? I will be using another user (user2) (not root) and we are on the same primary and secondary group. I copied everything including it's .profile and set the path accordingly. user1@hostnmae0:/home/user1 $ pkill java pkill: Failed to signal pid 1234:... (2 Replies)
Discussion started by: lhareigh890
2 Replies

6. IP Networking

iptables DNAT of outgoing destination port, unexpected behavior

Not sure if this should be here or in the security section. I am developing software that dynamically manipulates netfilter/iptables rules (through system() calls of the command strings, I'm not trying to hack the netfilter code). Basically, UDP messages that are sent by an application on, say,... (0 Replies)
Discussion started by: cjh19460
0 Replies

7. UNIX for Advanced & Expert Users

unexpected behavior bash, set -o vi, history -a, and HISTFILE

I am trying to get my history in sync in multiple bash sections and things aren't working the way I expect. Desired behavior, hitting esc-K in all bash sessions (same userid and machine) will use the same history. Observed behavior: Esc-k shows the history of the current session, rather than... (8 Replies)
Discussion started by: gg48gg
8 Replies

8. Shell Programming and Scripting

Expect command when triggered by launchd

Hi folks, Im having trouble with an expect command in a shell script I use to back up mac os x servers. This one is being run on a 10.8.2 Server as part of a larger bash script. The script executes perfectly all the way through when triggered on the command line, but when launchd triggers it at... (4 Replies)
Discussion started by: rowie718
4 Replies

9. Shell Programming and Scripting

Unexpected Echo Behavior

Hello all, I have a basic issue that I can't seem to search for since I'm not sure how to describe the behavior. Could anyone kindly assist the novice? (Sample) File Data: bundle-ppp-1/1.78 bundle-ppp-1/2.80 bundle-ppp-1/1.79 bundle-ppp-1/2.81 bundle-ppp-1/1.80 bundle-ppp-1/2.82... (6 Replies)
Discussion started by: sjrupp
6 Replies

10. Shell Programming and Scripting

Delete everything owned by a particular user

I want to delete all files and folders owned a user say abcuser in the folder /tmp . Can you please give me the command ? Thanks Matt (2 Replies)
Discussion started by: lijjumathew
2 Replies
fsdaemon(1M)															      fsdaemon(1M)

NAME
fsdaemon - pass-through daemon for processing system commands SYNOPSIS
fork] DESCRIPTION
The is a user level daemon that provides a mechanism to pass information between applications and common commands and library functional- ity, allowing certain applications to dynamically add functionality to a system. This is currently only supported for the class of APIs, such as: The API are not yet publicly available, but the commands that use the mentioned APIs depend on this daemon to always be running in the HP- UX environments. Options When is started, indicates whether it should fork a child process and exit the parent process or run just as the parent process and not return. A value of 1 for fork will make fork and exec a child process and then cause the parent process to exit. Kills the current running instance of Tests and waits until is ready to process commands. There is a window where could be started and not yet setup to process commands. The caller should invoke separately with the option to block until is ready to process commands. The entries to start are in the file. These entries be present to ensure correct functionality of the system. They should appear as one of the first entries in placing entries before entries in is dangerous and unsupported. The following are some of the HP-UX commands that use via the above APIs: and RETURN VALUE
: 0 Successful start of If invoked with the option, 0 is always returned. >0 Errno of failure that caused to fail to start. This applies only if was started with the option. ERRORS
If is not running, the errno will be returned by an application that invokes these APIs. If this happens, please see your system adminis- trator to make sure is properly running. EXAMPLES
To start such that it can be invoked without permanently blocking the calling process: To kill the currently running instance of To check to see if the currently running instance of is ready and able to process requests sent to it: The following entries for starting should appear in the file: WARNINGS
The APIs are not yet publicly available, but the commands that use the mentioned family of APIs depend on this daemon to always be running on HP-UX environments. The administrator is not expected to invoke the command from the shell prompt; it should always be started via an entry in This manpage is provided for administrator's trouble shooting purposes, and to allow the system administrator to repair the entries for this daemon in case of corruption. The interface/options provided in this manpage are HP-UX release specific, and may be different in future releases. AUTHOR
was developed by HP. SEE ALSO
fstyp(1M), mkboot(1M), mount(1M), fstatfsdev(3C), fstatvfsdev(3C), statvfsdev(3C), statfsdev(3C), inittab(4). fsdaemon(1M)
All times are GMT -4. The time now is 04:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy