任何人都可以賜教一下爲什麼這個代碼工作順利大有玄機:Perl fork爲什麼沒有回車/換行符會破壞代碼?
#!/usr/bin/perl
my $papa = $$;
my $pid;
$pid = fork;
die "Fork call has failed: $!" unless defined $pid;
if ($pid) {
# Dad code
while (1) {
print "Fix your room Charlie\n";
sleep(1);
}
} else {
# Child code
for (my $count = 0; $count < 5; $count++) {
print "Oh, not now dad...\n";
sleep(1);
}
local $SIG{TERM} = "IGNORE";
kill TERM => -$papa;
exit;
}
但如果我刪除跳給它突然不下一行?
#!/usr/bin/perl
my $papa = $$;
my $pid;
$pid = fork;
die "Fork call has failed: $!" unless defined $pid;
if ($pid) {
# Dad code
while (1) {
print "Fix your room Charlie";
sleep(1);
}
} else {
# Child code
for (my $count = 0; $count < 5; $count++) {
print "Not now dad...\n";
sleep(1);
}
local $SIG{TERM} = "IGNORE";
kill TERM => -$papa;
exit;
}
這可能是一些非常愚蠢的,或者是我有充分的理由,這將有助於我更好地瞭解打印的內件...或叉 (我知道的內件,一個孩子殺死其父親是不是很好,但要注意的父親已經進入了一個無限循環)
感謝提前:)