Ok here is my code..
The return of tid is usually about 2-3 off of the actual pid. It is driving me crazy trying to figure out why it will not give me the exact pid.
So when I try to kill the process, it will not kill, I suppose i could write one to do ps -u | grep ssh vars specific to this process, but i shouldn't have too. Any ideas?
EDIT here is the actual code pasted
- (void)startService {
NSString *temp = @"-D 8080 user@127.0.0.1 -N";
task = [[NSTask alloc] init];
[task setLaunchPath: @"/usr/bin/ssh"];
[task setArguments: [temp componentsSeparatedByString:@" "]];
NSPipe *input = [NSPipe pipe];
[task setStandardInput: input];
[task launch];
int tid = [task processIdentifier];
NSLog(@"Starting task: %i", tid);
}
- (void)stopService {
if ([self isRunning]) {
int tid;
tid = [task processIdentifier];
running = false;
[task terminate];
NSString *killTask = [NSString stringWithFormat:@"/bin/kill -KILL %i", tid];
//NSLog(@"Attepting to KILL: %i", tid);
system([killTask cStringUsingEncoding:NSASCIIStringEncoding]);
//[task ];
}
}