This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^CTraceback (most recent call last): | |
File "fork.py", line 11, in | |
time.sleep(1) | |
KeyboardInterrupt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ps -ef | grep 26556 | |
lex 26556 26555 0 21:40 pts/3 00:00:00 [python] <defunct> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> python fork_zombie.py | |
I created a child and now all I want to do is sleep… | |
Goodbye cruel world! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import fork, getppid, wait | |
from sys import exit | |
from time import sleep | |
pid = fork() | |
if pid == 0: | |
exit("Goodbye, cruel world") | |
else: | |
print "I created a child:", pid |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> python fork_wait.py | |
Hope my parent doesn't forget me this time! | |
Right now, my parent is 20037 | |
Right now, my parent is 20037 | |
Right now, my parent is 20037 | |
My child has finished processing. My work here is done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import fork, getppid, wait | |
from sys import exit | |
from time import sleep | |
pid = fork() | |
if pid == 0: | |
print "Hope my parent doesn't forget me this time!" | |
for _ in range(3): | |
sleep(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> python fork_orphan.py | |
Parent here, I just created child 19683 | |
Child process up in this. | |
Right now, my parent is 19682 | |
> Right now, my parent is 1 | |
Right now, my parent is 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import fork, getppid | |
from time import sleep | |
pid = fork() | |
if pid == 0: | |
print "I'm about to become an orphan!" | |
for _ in range(3): | |
sleep(1) | |
print "My parent is", getppid() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> python fork_ppid.py | |
Parent here, I just created child 19741 | |
Child process up in this. | |
My parent is 19740 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import fork, getppid | |
from time import sleep | |
pid = fork() | |
if pid == 0: # We're in the child process | |
print "Child process up in this." | |
print "My parent is", getppid() | |
else: | |
print "Parent here, I just created child", pid |