1

I am trying to fork a process using python 2.4 on AIX 5.1 , I am using the following code

def runcmd(cmd):

    (pid, fd) = pty.fork()
    argv = cmd.split()
    if not pid:
            print "In child process"
            #time.sleep(1) 
            os.execv(argv[0],argv)
            sys.exit()

    print "In parent process"

if __name__ == "__main__":
        print "In main"
        runcmd("/bin/sh cmd1 -l")

The problems is that this code hangs , it only prints "In main" and it just stays there locked. If , however I uncomment the line with "time.sleep(1)" it executed fine , it forks and everything is ok , it prints "In main" and then "In parent process" what it's supposed to do.

Out of my knowledge execv overwrites the image of the executing process and it does not return , but I cannot understand why this piece of code hangs on my machine. Please note that this code works fine with python 1.5 , why it doesn't on 2.4 is beyond me.

Can anyone help ? Is execv executing to fast and it messes up also the parent image (I know this sound silly by it seems that it's doing just that , or at least something similar to this)?

Thanks, Mircea

Mircea
  • 393
  • 1
  • 4
  • 11
  • Does it behave the same when you use `os.fork` (since you're not actually using the PTY)? – Fred Foo Jan 05 '12 at 16:35
  • can you test this on other OSs? Are you sure it is AIX specific? Good luck. – shellter Jan 05 '12 at 17:40
  • I have tested this in RH environments using the same python version and it behaves just fine , no hang whatsoever. I was able to repro this only on AIX machines ... very strange – Mircea Jan 06 '12 at 06:53
  • And `os.fork` seems to be working just fine. – Mircea Jan 06 '12 at 07:04

0 Answers0