想要在perl脚本中执行perl脚本

时间:2011-08-01 15:35:34

标签: perl process exec fork

我需要perl的帮助。我是新手。 我想从我的父perl脚本执行perl脚本并涵盖以下场景:

if (my child script takes more time than my time limit)
{
    I need to kill the child script with a return code 
    logged into my parent script log file
}

if (my child script failed to execute)
{
     I need to write a new RC to my parent script logfile 
     by looking at my child script exit status
} 

任何正文都可以为此提供代码,例如如何使用fork,exec和process相关命令 当我的父脚本被执行时获取子进程的进程ID?

2 个答案:

答案 0 :(得分:1)

perlipc(进程间通信)手册页是一个很好的起点。

答案 1 :(得分:0)

一般而言:

fork()返回一个整数,如果失败则返回undef。

检查整数的值

  1. 如果它是0,那么你就在孩子身边,并且你执行幼稚的任务。
  2. 如果它不是0那么你在父母中,并且你有孩子的pid,所以你等待它,或者根据需要收获它。
  3. davorg已经提到过perlipc文档中这种代码的骨架的一个很好的例子。

相关问题