On Aug 31, 2015, at 9:50 PM, Scott Ribe <[email protected]> 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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]