perl网络编程学习笔记(二)

2.1    进程

    两种使用子进程的方法:fork()函数和system()、exec()函数

2.1.1    fork()函数

    $pid = fork()
    派生一个新进程,在父进程中返回子进程的pid,在子进程中返回0,发生错误时返回undef,并将$!设置为恰当的错误消息。

    $pid=getppid()
    返回父进程的pid。

    $$=getppid()
    $$变量保持当前的进程的pid。

2.1.2    system()函数和exec函数

    $status = system('command and arguments');
    $status = system('command', 'and', 'arguments');
    运行成功返回0,不能开始运行返回-1,以错误终止返回程序的终止状态。

    $status = exec('command and arguments');
    $status = exec('command', 'and', 'arguments');

    exec()和system()的区别是:如果运行成功,exec()从不返回,因为进程没了,除了标准句柄之外的文件句柄将自动关闭。

posted on 2009-02-04 09:56  starspace  阅读(543)  评论(1编辑  收藏  举报

导航