First page Back Continue Last page Overview Graphics

Python scripts with exec*()

import os, sys

while True:

pid = os.fork()

if pid == 0:

args = ("useless","child.py", "abc")

os.execv('/usr/bin/python', args )

assert False, "child.py couldn't be started"

else:

print 'ProcessID of Child:', pid

if raw_input( ) == 'q': break

The child process, which should be in the same directory like the python script, should look like following example:

import sys

print "value of argv", sys.argv

print "I am a script, called from a program called %s" % (sys.argv[1])