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

Using this script:

#!/usr/bin/perl use strict; use diagnostics; use warnings; my $pid = fork || exec 'play', '/home/ra/Desktop/trek2.mp3'; print "My PID is *$pid*\n"; sleep 5; kill $pid;

The file starts playing, and I would hope that it stops playing after 5 seconds, but it doesn't. Here's the terminal output before the 5 second cut-off:

ra@eagle ~/Local/Code/amudclient/test/playsound $ ./playsound.pl My PID is *21417* /home/ra/Desktop/trek2.mp3: File Size: 506k Bit Rate: 135k Encoding: MPEG audio Info: 2017-09-26T15:54 Channels: 2 @ 16-bit Track: 309 Samplerate: 44100Hz Album: This Week in Trek Replaygain: off Artist: Michael Gaines and Darrell Skeels Duration: 00:00:30.07 Title: This Week in Trek Episode 309 In:17.6% 00:00:05.29 [00:00:24.77] Out:233k [ =|= ] Cl +ip:0

And the terminal output, once the file stops playing naturally.

ra@eagle ~/Local/Code/amudclient/test/playsound $ ./playsound.pl My PID is *21364* /home/ra/Desktop/trek2.mp3: File Size: 506k Bit Rate: 135k Encoding: MPEG audio Info: 2017-09-26T15:54 Channels: 2 @ 16-bit Track: 309 Samplerate: 44100Hz Album: This Week in Trek Replaygain: off Artist: Michael Gaines and Darrell Skeels Duration: 00:00:30.07 Title: This Week in Trek Episode 309 In:17.0% 00:00:05.11 [00:00:24.96] Out:225k [ -====|====- ] Cl +ip:0 raIn:28In:In:In:29.7%In:3In:3In:In:In:32In:InInIn:46.6% 00In: +47.3% 0In:47InIn:100% 00:00:30.07 [00:00:00.00] Out:1.33M [ ===|== += ] Clip:0 Done.

Replies are listed 'Best First'.
Re^5: Killing a child process
by hippo (Archbishop) on Oct 03, 2017 at 08:20 UTC
    kill $pid;

    The first argument to kill should be the signal, not the PID. Since you didn't test the return value of kill you haven't spotted the error.