Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 884455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:45:13+00:00 2026-05-15T12:45:13+00:00

I have an application that checks its command line parameters and stores values in

  • 0

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:

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:[args objectAtIndex:0]];
[task launch];
[task release];
[NSApp terminate:nil];

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?

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.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T12:45:14+00:00Added an answer on May 15, 2026 at 12:45 pm

    There are plenty of examples on the web, but this one (also below) looks like it has all the code you need. There are more detailed explanations out there, as well.

    // gcc -Wall -arch i386 -arch ppc -mmacosx-version-min=10.4 -Os -framework AppKit -o relaunch relaunch.m
     
    #import <AppKit/AppKit.h>
     
    @interface TerminationListener : NSObject
    {
        const char *executablePath;
        pid_t parentProcessId;
    }
     
    - (void) relaunch;
     
    @end
     
    @implementation TerminationListener
     
    - (id) initWithExecutablePath:(const char *)execPath parentProcessId:(pid_t)ppid
    {
        self = [super init];
        if (self != nil) {
            executablePath = execPath;
            parentProcessId = ppid;
     
            // This adds the input source required by the run loop
            [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(applicationDidTerminate:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
            if (getppid() == 1) {
                // ppid is launchd (1) => parent terminated already
                [self relaunch];
            }
        }
        return self;
    }
     
    - (void) applicationDidTerminate:(NSNotification *)notification
    {
        if (parentProcessId == [[[notification userInfo] valueForKey:@"NSApplicationProcessIdentifier"] intValue]) {
            // parent just terminated
            [self relaunch];
        }
    }
     
    - (void) relaunch
    {
        [[NSWorkspace sharedWorkspace] launchApplication:[NSString stringWithUTF8String:executablePath]];
        exit(0);
    }
     
    @end
     
    int main (int argc, const char * argv[])
    {
        if (argc != 3) return EXIT_FAILURE;
     
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     
        [[[TerminationListener alloc] initWithExecutablePath:argv[1] parentProcessId:atoi(argv[2])] autorelease];
        [[NSApplication sharedApplication] run];
     
        [pool release];
     
        return EXIT_SUCCESS;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you have a Donate form tied into a Paypal… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer I doubt it would be recorded anywhere in the event… May 15, 2026 at 3:20 pm
  • Editorial Team
    Editorial Team added an answer You can do this on most systems using popen (or… May 15, 2026 at 3:20 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.