开发者

Want to execute a perl script within a perl script

开发者 https://www.devze.com 2023-03-25 15:06 出处:网络
I need a help on perl. I am new to it. I want to execute a perl script from my parent perl script and cover the following scenarios:

I need a help on perl. I am new to it. I want to execute a perl script from my parent perl script and cover the following scenarios:

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
} 

Can any body provide code for this like how to use fork, exec and process related commands to fetch process id of children when my parent script gets executed?


The perlipc (inter-process communication) man page would be a good place to start.


Generally:

fork() returns an in integer, undef if it fails.

You check the value of the integer

  1. if it is 0 then you're in the child, and you run your childish tasks.
  2. if it is not 0 then your in the parent, and you have the pid of the child, so you wait for it, or reap it as needed.

There's a good example of the skeleton of this kind of code in the perlipc document that davorg already mentioned.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号