Add a timeout to NSTask

February 18, 2011 by · Leave a Comment 

// 1 minute timeout
NSDate *terminateDate = [[NSDate date] addTimeInterval:60.0];
while ((theTask != nil) && ([theTask isRunning]))	{
	if ([[NSDate date] compare:(id)terminateDate] == NSOrderedDescending)	{
		NSLog(@"Error: terminating task, timeout was reached.");
		[theTask terminate];
	}
	[NSThread sleepForTimeInterval:1.0];
}

About admin

Comments are closed.