FROM : Matt Mashyna
DATE : Thu Feb 14 19:48:40 2008
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;
}
DATE : Thu Feb 14 19:48:40 2008
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;
}
| Related mails | Author | Date |
|---|---|---|
| Matt Mashyna | Feb 14, 19:48 | |
| Dave Camp | Feb 14, 20:32 | |
| Dave Camp | Feb 14, 20:41 | |
| Uli Kusterer | Feb 14, 20:54 |






Cocoa mail archive

