Re: How to terminate an NSTask whenever my app terminates?
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