I have a larger program (150 lines or so) but this seems to be the only issue I have. I have managed to cut down the problem and have made it into a smaller program. Essentially, it forks the program and tries to execute a linux command (I am running this with ubuntu). I get the following output:
Current instruction is bin/ls
Current instruction is bin/ls
Child PID is 984
Traceback (most recent call last):
File "./Test.py", line 17 in <module>
makeFork("bin/ls")
File "./Test.py", line 12, in makeFork
os.execl(instruction, instruction)
File "/usr/lib/python2.7/os.py", line 314, in execl
execv(file, args)
OSError: [Errno2] No such file or directory
Parent PID is 4
Below is the code for the program
import os
from time import sleep
os.system("clear")
def makeFork(instruction):
PID = os.fork() #Creating a fork for the child process
sleep(2)
print("Current instruction is " + instruction)
if PID == 0:
print("\nChild PID is " + format(os.getpid()))
os.execl(instruction, instruction)
sleep(2)
print("\nParent PID is " + format(os.getppid()))
makeFork("bin/ls")
Where am I going wrong?