0

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 ];
 }
}
  • Please post the actual code you're using. The code as provided won't compile (it's trying to log `id`, which is a type and not the process identifier), and it leaves out important details such as what arguments you're passing to the invocation of ssh. A version of the above code that's modified to compile and run shows `-processIdentifier` returning the expected value, so the problem is hidden by the information you've omitted. – bdash Jan 22 '13 at 09:12
  • Ok, repasted the code realized previously that I had named an int id and that was problematic, but even after changing id to tid I still have same issues. – Richard Williamson Jan 22 '13 at 21:47
  • I'm still unable to reproduce the behavior you describe. The only remaining explanation that comes to mind is that perhaps you have something in your ssh_config file that could be causing ssh to fork itself. You could rule this out by passing -F /dev/null as arguments to your ssh invocation. That will have ssh use /dev/null as a configuration file so it'll use the built-in default configuration. – bdash Jan 22 '13 at 22:09
  • Tried -F /dev/null, still the same issues.Forking has to be happening, because the [task isRunning] says its not running, but it is successful. I'll look at my config file. I might try it in a virtual machine. – Richard Williamson Jan 22 '13 at 22:30
  • It could be worth looking at what, if anything, the task is writing to stdout / stderr. That may provide a hint as to what is happening, particularly if you run ssh with one or more -v arguments to increase the verbosity. – bdash Jan 22 '13 at 22:45
  • OK I realized -f tells ssh to fork, removed it and it stays alive. – Richard Williamson Jan 22 '13 at 23:07
  • I don't see -f anywhere in your code above. – bdash Jan 22 '13 at 23:12

0 Answers0