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:<
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.
First of all, execlp
is rarely used today. In most cases, you'd use the subprocess module, like this:
subprocess.call(['python', 'child.py'])
The first argument of execlp is the file you want to execute.
The latter arguments form the argument array to that program (sys.argv in Python). The first argument is then the name the program got invoked with. For example, Python sets the name to '-c'
if the program is being run with the -c
option. Similarly, grep behaves differently depending on the first argument, so that users can execute rgrep
to imply grep -r
.