Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Killing a child process

by ikegami (Patriarch)
on Oct 03, 2017 at 07:51 UTC ( [id://1200582]=note: print w/replies, xml ) Need Help??


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

What's not working? What error did it return?

Replies are listed 'Best First'.
Re^4: Killing a child process
by Anonymous Monk on Oct 03, 2017 at 08:11 UTC

    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.
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200582]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found