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