views:

222

answers:

1

I have my Cocoa app executing a shell script. I want to make it so that the shell script automatically kills itself if it finds that the host .app is not running. Right now what I have is the shell script polls using the UNIX "ps" command every time before it executes a command, and then kills itself if the app is not running. However this polling wastes resources, so is there a better way to do this?

I'm using Mac OS X 10.6 using the default bash shell.

A: 

What's unclear in your question is how you're presently polling. Is the method you're using to poll wasteful? Or do you want to eliminate polling altogether?

The bash variable PPID is the process id of its parent process. So

ps -p ${PPID}
if [ $? -eq 0 ]; then exit; fi

seems fairly efficient.

The alternative to polling would be to have the app signal the shell before it exits.

J. A. Faucett