我在 perl 脚本中有以下设计:
my $child_pid = fork;
if( ! $child_pid ){
# do some stuff...
exec( $user_specified_command );
else{
# wait for child to exit
waitpid( $child_pid, 0 );
}
# Continue with the script
我有兴趣在子执行时在父级中收到警报,以便我可以获得一些详细信息$user_specified_command
(特别是用于lsof
确定 stdout 是否被重定向到常规文件)。结果将是这样的:
my $child_pid = fork;
if( ! $child_pid ){
# do some stuff...
exec( $user_specified_command );
else{
# wait until the child exec's
wait_child_exec();
# do some stuff...
# wait for child to exit
waitpid( $child_pid, 0 );
}
# Continue with the script
我可以循环和 grepps
输出直到名称更改,但似乎 exec 是一个足够严重的事件,有更好的方法。