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()从不返回,因为进程没了,除了标准句柄之外的文件句柄将自动关闭。

相关文章:

  • 2022-12-23
  • 2021-12-23
  • 2022-01-07
  • 2021-11-08
  • 2021-06-28
  • 2021-06-06
  • 2021-12-24
  • 2021-05-28
猜你喜欢
  • 2021-05-31
  • 2022-02-08
  • 2021-09-30
  • 2021-05-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案