• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to terminate an NSTask whenever my app terminates?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to terminate an NSTask whenever my app terminates?


  • Subject: Re: How to terminate an NSTask whenever my app terminates?
  • From: Ken Thomases <email@hidden>
  • Date: Mon, 31 Aug 2015 23:55:52 -0500

On Aug 31, 2015, at 9:50 PM, Scott Ribe <email@hidden> wrote:
>
> Normally, when a parent exits, all child processes are killed.

This is not true.

> This is not specific to terminal/tty sessions.

Yes, it is.

Try the following program.  The parent will print the child's PID and exit (by falling out of main()).  Then do a "ps xww -p <the child PID>".  You'll see the child is still running.  You can kill it when satisfied.

Nothing special was done to detach the child from the parent and nothing need be done.

Regards,
Ken

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>


int main(void)
{
    int child = fork();
    if (child == -1)
    {
        perror("fork");
        exit(EXIT_FAILURE);
    }
    else if (child == 0)
    {
        // in child
        printf("sleeping...\n");
        while (1) sleep(1);
    }
    else
    {
        // in parent
        printf("child %d\n", child);
    }

    return 0;
}


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


References: 
 >How to terminate an NSTask whenever my app terminates? (From: Jens Alfke <email@hidden>)
 >Re: How to terminate an NSTask whenever my app terminates? (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: How to terminate an NSTask whenever my app terminates?
  • Next by Date: Re: How to terminate an NSTask whenever my app terminates?
  • Previous by thread: Re: How to terminate an NSTask whenever my app terminates?
  • Next by thread: Re: How to terminate an NSTask whenever my app terminates?
  • Index(es):
    • Date
    • Thread