• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Obj-C server and signal handling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Obj-C server and signal handling


  • Subject: Obj-C server and signal handling
  • From: Matt Mashyna <email@hidden>
  • Date: Thu, 14 Feb 2008 13:48:40 -0500

I whipped up a little cocoafied server without a UI and it works great, easy to read and all that good stuff but I'm stuck on one last thing. I'm trying to catch a quit signal from Activity Monitor. Force Quit definitely works but I'd like to be able to catch whatever signal the Activity Monitor sends for the polite quit. Doesn't seem to be sending a SIGQUIT, SIGTERM or anything like that. Sometimes I see a SIGINT. I can catch signals sent from the terminal fine. Is this the wrong way to go about this?

Now that I think about it, it would be even better to be able to have a delegate object to catch applicationWillTerminate and shutdown more gracefully. I'm not sure how I would do that without loading up a nib.

Here's my main.m which works to catch some signals and exit:

static BOOL	keepRunning = YES;
static void
signal_handler(const int signum)
{
//	if(signum == SIGTERM)
		keepRunning = NO;
	NSLog(@"signal=%d", signum);
}

int main(int argc, char *argv[])
{
  	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSApplicationLoad();
	[NSApp setDelegate:del];

	AppController*	myServer = [[AppController alloc] init];

	signal(SIGHUP, signal_handler);
	signal(SIGINT, signal_handler);
	signal(SIGQUIT, signal_handler);
	signal(SIGABRT, signal_handler);
	signal(SIGTERM, signal_handler);

	NSRunLoop *loopy = [NSRunLoop currentRunLoop];
	while (keepRunning && [loopy runMode:NSDefaultRunLoopMode
		beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]]);

	[pool release];

	return 0;
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Obj-C server and signal handling
      • From: Uli Kusterer <email@hidden>
    • Re: Obj-C server and signal handling
      • From: Dave Camp <email@hidden>
  • Prev by Date: Re: Newbie Issue: isDescendantOf: error
  • Next by Date: Re: Newbie Issue: isDescendantOf: error
  • Previous by thread: Re: Changing app menu title programmatically
  • Next by thread: Re: Obj-C server and signal handling
  • Index(es):
    • Date
    • Thread