in reply to Re^4: Killing a child process
in thread Killing a child process

I wonder if there's any way to check that the sound file is still playing?

I would guess that the sound not playing anymore would normally be closely associated with the process terminating. There are probably exceptions, e.g. if the audio data is buffered or something, but personally I would probably first go with the aforementioned assumption, and only investigate further if problems arise (or if this application needs to be ported to a lot of different machines). So as far as I can tell, ->finish calls waitpid under the hood, which means that it should return when the process ends, and hopefully when audio file is done playing. The following test seems to confirm it - at least on my machine the sound stops playing right when the process terminates:

use IPC::Run qw/start/; use Time::HiRes qw/gettimeofday tv_interval/; my $t0 = [gettimeofday]; my $h = start ['play','-q','/home/myname/soundfile.wav', 'trim','0','5']; printf " start: %.03f s\n", tv_interval($t0); $h->finish; printf "finish: %.03f s\n", tv_interval($t0); __END__ start: 0.001 s finish: 5.143 s

Update: Other than waitpid for children, a generic way to see if another process is reachable is kill 'ZERO', $pid:

If SIGNAL is either the number 0 or the string ZERO (or SIGZERO), no signal is sent to the process, but kill checks whether it's possible to send a signal to it (that means, to be brief, that the process is owned by the same user, or we are the super-user). This is useful to check that a child process is still alive (even if only as a zombie) and hasn't changed its UID. See perlport for notes on the portability of this construct.