私は、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、標準出力が通常のファイルにリダイレクトされているかどうかを確認するために使用します)。結果は次のようになります。
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
名前が変わるまで出力をループしてgrepすることもできますpsが、 exec はより良い方法があるほど深刻なイベントのようです。