Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execlp() in python

Tags:

python

I was reading programming python 4th edition by Mark Luze, Oreilly, by teaching myself. There's an example on how to fork a child process, which I do not quite understand:

os.execlp('python', 'python', 'child.py', #other args#)

In an interactive shell(like bash), I know I can type python child.py #args# to ask python interpreter to run child.py with args. Why are there TWO 'python' in the execlp() function? If I put only one python in the function, I would get an error complainting cannot find file or directory, which is the 1st args of child.py

like image 764
comicosmos Avatar asked Nov 18 '12 12:11

comicosmos


1 Answers

The first argument is the program to execute (found on the PATH). The rest are the sys.argv arguments to the program.

The first such argument is the program name used to invoke it, and the display value used in the OS process list. It is the value of sys.argv[0] in a python script.

like image 160
Martijn Pieters Avatar answered Sep 24 '22 21:09

Martijn Pieters