Code: Select all
import sys
import os
print("Start: " + str(os.getpid()))
sys.stdout.flush()
if len(sys.argv) > 1:
pid = os.fork()
if pid == 0:
os.execvp(sys.argv[1], sys.argv[1:])
elif pid > 0:
print("Fork: " + str(pid))
sys.stdout.flush()
x = os.wait()
if x[0] != pid: # NEEDED
os.waitpid(pid,0) # NEEDED
print("End: " + str(x[0]))
else:
print("Fork failed", file=sys.stderr)
sys.exit(1)
else:
print("End")
sys.stdout.flush()
< /code>
Ich führe dies mit dem folgenden Befehl aus: < /p>
python test.py python test.py ps
Code: Select all
Start: 999773
Fork: 999777
Start: 999777
Fork: 999781
PID TTY TIME CMD
999773 ? 00:00:00 python3
999777 ? 00:00:00 python3
999781 ? 00:00:00 ps
End: 999781
End: 999774
Code: Select all
Start: 1000822
Fork: 1000830
End: 1000824
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = '/usr/bin/python3'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/usr/bin/python3'
sys.base_prefix = '/usr'
sys.base_exec_prefix = '/usr'
sys.executable = '/usr/bin/python3'
sys.prefix = '/usr'
sys.exec_prefix = '/usr'
sys.path = [
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f27b84f7740 (most recent call first):