Hi,

I'm writing an app that uses an NSTask to spawn a long-lived process.
When my app is force-quit or otherwise SIGKILLed, the spawned process
gets re-parented and hangs around indefinitely. I was hoping to use
process groups to tackle this, but although setpgid() reports success,
it doesn't seem to have had any effect. Here is the code I am using:

        myTask = [[NSTask alloc] init];

        // ...snipped code for setting up path, args, pipes for
stdin/stdout/stderr, etc...

        pid_t pgrp = setpgrp();
        if (pgrp < 0)
        {
                NSLog(@"could not create new pgrp");
                pgrp = getpgrp();
        }

        [myTask launch];

        pid_t taskpid = [myTask processIdentifier];
        int res = setpgid(taskpid, pgrp);
        pid_t newpgrp = getpgid(taskpid);
        NSLog(@"pgrp = %d, res = %d, newpgrd = %d", pgrp, res, newpgrp);

The call to setpgrp() is successful (the parent process has the same
pgid as its pid) and the NSLog reports "pgrp = 3166, res = 0, newpgrd
= 3166". However, "ps -xj" reports that the child process does not
have 3166 as its pgid (FWIW, it has pid/ppid/pgid 3167/3166/3167).

What am I missing here? Has anyone else had any success setting the
process group on a process spawned using NSTask?

Thanks,
Hamish
_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to