This commit is contained in:
Juanjo 2024-10-03 12:03:19 +02:00
commit e3b9139653
1 changed files with 20 additions and 0 deletions

20
fork1.py Normal file
View File

@ -0,0 +1,20 @@
# fork solo funciona en unix/macos
import os
def padre():
while True:
newpid = os.fork()
if newpid == 0:
hijo()
else:
pids = (os.getpid(), newpid)
print("Padre: %d, Hijo: %d\n" % pids)
reply = input("Pulsa 's' si quieres crear un nuevo proceso")
if reply != 's':
break
def hijo():
print('\n>>>>>>>>>> Nuevo hijo creado con el pid %d a punto de finalizar<<<<<' % os.getpid())
os._exit(0)
padre()