2007年11月6日星期二

Perl : system / exec / fork

system "date";
当子进程运行时,Perl 会耐心地等待其结束再继续运行。

exec "date";
Perl进程离开,只有运行date命令的进程。date结束时,Perl 不会回来。

fork

#!/usr/bin/perl

defined( my $pid = fork ) or die "Cannot fork : $!";

unless ($pid) {
    #子进程在这里
    exec "date";
    die "cannot exec date: $!";
}

#父进程在这里
waitpid( $pid, 0 );

没有评论:

发表评论