views:

22

answers:

1

Hi everyone, I was wondering if there was a way that I could get notifications of when a system process from /usr/sbin starts and finishes. Is it possible to attach NSTask to the running process without launching a new one? Preferably without polling please :!

A: 

For UI process you can use NSRunningApplication. You can observe the "terminated" property to know when it finishes. You can listen to NSWorkspaceWillLaunchApplicationNotification to know when an application will be launched.

Since you're not running a UI application the above probably won't work. You'll have to use more low level BSD calls. Here's an example of how you can know when an process terminates: http://developer.apple.com/mac/library/technotes/tn/tn2050.html#SECKQUEUES

Good luck!

Leibowitzn
THANK YOU! That is exactly what I've been looking for. I have am having problems implementing the kqueue sample into my code. NoteExitKQueueCallback is undeclared and noteExitKQueueRef is undeclared. I just put a CFFileDescriptorRef in front of if. But it seems that in order to create a CFFileDescriptorCallback you need to have a CFFileDescriptor. But the CFFileDescriptor is created after the callback would.
Alex Zielenski
EDIT: Nevermind. I got it working by adding the Callback method into my header file. But the code doesn't seem to work if the process is executed after I call the method.
Alex Zielenski
Yea, I don't know of a good way to observe newly launched command line applications.
Leibowitzn