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.

In reply to Re^5: Killing a child process (updated) by haukex
in thread Killing a child process by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.