title: Relaunching a cocoa app
body: <p>I have an application that checks its command line parameters and stores values in persistent stores.  One of those is a password that I don't want sticking around for people to see with 'ps' and friends.  The approach I'm currently looking at is to, after I've stored the values I need, relaunch the process without the command line parameters.  My naive approach is this, where args[0] is the path to the application:</p>
  
  <pre><code>NSTask *task = [[NSTask alloc] init];
  [task setLaunchPath:[args objectAtIndex:0]];
  [task launch];
  [task release];
  [NSApp terminate:nil];
  </code></pre>
  
  <p>The child is run.  However, when my app is terminated the child doesn't seem to orphan but gets stuck.  Am I just way off on this one?</p>
  
  <p>More info:  So it seems that when I call [NSApp terminate:nil] the NSTask that was launched gets stuck, but if I just exit() then it works fine.  However, I'm concerned that things that are open (keychain, plist, etc.) will be in a bad state if I do that.</p>
  
  <p>And note that lots of example code out there is about some watchdog-like process that restarts a separate process when needed.  I'm trying to restart the current process that's already running from within that same process.</p>