cc: ast-developers@research.att.com
Subject: Re: [ast-developers] ksh process group problem
--------


ksh93 uses posix_spawn() rather than fork/exec to run a simple command for
performance reasons.  However, posix_spawnv() doesn't have a way to
set the terminal group before the exec().  The parent process sets the
terminal group which leads to the race.

There is a simple change you can make to a program to guarentee that
the terminal will get set at the beginning of the program.
You can add two lines.  One line is
        #include        <termios.h>

and for the other line  
                tcsetpgrp(2,getpgrp());
Alternatively, you can write a program that does these two lines and
then execs the original program.

> I am seeing an intermittent problem on Red Hat Enterprise Linux 5.4 and 5.6, 
> and
>  HP-UX 11.0 and 11.31.
> The processes launched from the AST ksh sometimes "own" the terminal, and 
> someti
> mes don't.
> 
> 
> Output from the test program below demonstrates the issue:
> 
> 
> [fbg@sturgeon ~]$ /opt/ast/bin/ksh
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8678  MY_pgrp=8678 STDIN_PGRP:8674 --DO NOT own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8679  MY_pgrp=8679 STDIN_PGRP:8679 --own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8680  MY_pgrp=8680 STDIN_PGRP:8680 --own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8681  MY_pgrp=8681 STDIN_PGRP:8681 --own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8682  MY_pgrp=8682 STDIN_PGRP:8674 --DO NOT own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8683  MY_pgrp=8683 STDIN_PGRP:8683 --own terminal
> 
> $ /tmp/testprocessgroup_linux64
> 
> PID: 8684  MY_pgrp=8684 STDIN_PGRP:8674 --DO NOT own terminal
> 
> $
> 
> 
> 
> 
> [fbg@sturgeon pgrp]$ cat testprocessgroup.c
> #include <stdio.h>
> #include <sys/types.h>
> #include <unistd.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> 
> int main(int argc, char **argv)
> {
>     int devtty;
> 
> 
>     printf("PID:%5lu  MY_pgrp=%d STDIN_PGRP:%d --%s\n",
>                getpid(),
>                getpgid(getpid()),
>                tcgetpgrp(fileno(stdin)),
>                tcgetpgrp(fileno(stdin)) == getpgid(getpid()) ? "own terminal" 
> : 
> "DO NOT own terminal" );
> 
> 
>     return(0);
> }
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> (attachment  1   171/10586              text/html "1.att")
> 
> _______________________________________________
> ast-developers mailing list
> ast-developers@research.att.com
> https://mailman.research.att.com/mailman/listinfo/ast-developers
> 

David Korn
d...@research.att.com
_______________________________________________
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to