fork2
This commit is contained in:
parent
fe3cbb5151
commit
914db33762
|
@ -0,0 +1,18 @@
|
||||||
|
from multiprocessing import Process
|
||||||
|
import os
|
||||||
|
|
||||||
|
def hijo():
|
||||||
|
print("Padre: %d, Hijo: %d\n" % ( os.getppid(),os.getpid()))
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
|
def padre():
|
||||||
|
while True:
|
||||||
|
p = Process(target=hijo)
|
||||||
|
p.start()
|
||||||
|
print ("\nNuevo hijo creado " , p.pid)
|
||||||
|
p.join()
|
||||||
|
reply = input("Pulsa 's' si quieres crear un nuevo proceso\n")
|
||||||
|
if reply != 's':
|
||||||
|
break
|
||||||
|
if __name__ == '__main__':
|
||||||
|
padre()
|
|
@ -1,4 +1,4 @@
|
||||||
# Ejemplos de fork() con python
|
# Ejemplos de fork() con python :hourglass:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
# fork solo funciona en unix/macos
|
# fork solo funciona en unix/macos
|
||||||
|
@ -25,8 +25,7 @@ padre()
|
||||||
```
|
```
|
||||||
> **fork** solo funciona en unix/macos
|
> **fork** solo funciona en unix/macos
|
||||||
|
|
||||||
:hourglass:
|
|
||||||
|
|
||||||
<i class="mdi mdi-ubuntu"></i>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue