[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why does NSTask setpgrp on sub processes?
From: |
Derek Zhou |
Subject: |
Re: why does NSTask setpgrp on sub processes? |
Date: |
Wed, 20 Jan 2010 22:54:07 -0800 |
User-agent: |
KMail/1.12.4 (Linux/2.6.31; KDE/4.3.4; i686; ; ) |
On Wednesday 20 January 2010 03:36:49 am Richard Frith-Macdonald wrote:
>
> On 20 Jan 2010, at 09:48, Derek Zhou wrote:
>
> > Oops, hit send too soon.
> >
> > #import <Foundation/Foundation.h>
> >
> > int main(int argc, char** argv)
> > {
> > NSTask* editor = [NSTask new];
> > [editor setLaunchPath: @"vi"];
> > [editor launch];
> > [editor waitUntilExit];
> > NSLog(@"finished\n");
> > }
> >
> > with the setpgrp (current behavior) it will hang because vi cannot get hold
> > of the tty.
> > without the patch which basically disable setpgrp vi will show and after
> > you close vi
> > this program will exit.
> > I can add tcsetpgrp after the launch so vi can get hold of the tty but then
> > after vi
> > exit tty control is not back to my prog but the shell. I have to fg or send
> > SIGCONT
> > to continue my prog.
> > I see what you mean, currently it is trying to send signal to the new
> > group.
> > But how many cases you really want to do that instead of just sending to
> > the single
> > process? Also by default if parent got killed all children got killed
> > (SIGHUP? I
> > am not sure) so the behavior is still roughly unchanged.
>
> After looking at and trying out the above program, it seems there was a
> problem, but your diagnosis was wrong.
>
> The issue was not that NSTask changes the process group (which it should),
> but rather that it was failing to detach the process from the controlling
> terminal (except when using pseudo-terminals). I have copied the code used
> with pseudo terminals so that it's always used.
I see you added the setsid and terminal detach and my program works. The minor
annoyance of having the launched task in a new session and group is that
standard shell job control (^Z, jobs, fg, bg) does not work; I'd have to
send signal to the process manually . Well I guess that's the price you pay
if you have to be compatible with the "golden" standard. Thanks for the
quick fix!
Derek
ps: I think you want this:
Index: configure.ac
===================================================================
--- configure.ac (revision 29340)
+++ configure.ac (working copy)
@@ -938,7 +938,7 @@
#--------------------------------------------------------------------
# These functions needed by NSTask.m
#--------------------------------------------------------------------
-AC_CHECK_FUNCS(killpg setpgrp setpgid)
+AC_CHECK_FUNCS(killpg setpgrp setpgid setsid)
if test "x$ac_cv_func_setpgrp" = xyes; then
AC_FUNC_SETPGRP
fi
- Re: why does NSTask setpgrp on sub processes?, Derek Zhou, 2010/01/20
- Re: why does NSTask setpgrp on sub processes?, Richard Frith-Macdonald, 2010/01/20
- Re: why does NSTask setpgrp on sub processes?, Derek Zhou, 2010/01/20
- Re: why does NSTask setpgrp on sub processes?, Richard Frith-Macdonald, 2010/01/20
- Re: why does NSTask setpgrp on sub processes?, Derek Zhou, 2010/01/20
- Re: why does NSTask setpgrp on sub processes?, Derek Fawcus, 2010/01/20