note
roboticus
<p>Not completely true. Using fork is a natural way to perform processes in the background.</p>
<c>
$ cat forkit.pl
#!/usr/bin/env perl
use strict;
use warnings;
my $pid = fork();
if ($pid) {
print "Parent is exiting now!\n";
}
else {
print "Child is waiting a bit\n";
sleep 15;
print "Child is done!\n";
}
$ perl forkit.pl
Parent is exiting now!
Child is waiting a bit
$ date
Fri Aug 14 10:22:06 EDT 2015
$ date
Fri Aug 14 10:22:15 EDT 2015
$ Child is done!
</c>
<p>There are differences on different operating systems, to be sure. Some processes could be killed on some operating systems (though I've not experienced it myself). You can accumulate zombie processes if you don't take steps to avoid it. If you're going to use fork, you need to educate yourself on what it does and doesn't do on your platform.</p>
<p>...[roboticus]</p>
<p><i>When your only tool is a hammer, all problems look like your thumb.</i></p>
1138461
1138568