[EMAIL PROTECTED] wrote:
> Hi there
>
> I'm stuck with system(). According to some posts, system() is passing SIGINT
> and SIGQUIT to it's child, yet this doesn't seem to work. I've boiled the
> code down to the following lines. (Please note that 'alsaplayer' is a console
> soundfile player that honors SIGINT and SIGQUIT by immediately quitting.)
>
> sub controler
> {
> my $pid = fork;
> if (!$pid) { &player(); }
> while (!-e "stop") { sleep(10); }
> kill('QUIT', $pid);
> }
Both your parent and child processes are executing the 'while'
and 'kill' statements.
> sub player
> {
> system("alsaplayer -q song.mp3");
> sleep;
> }
>
> The controler forks off the player child which system()-implicitly forks
> again and runs alsaplayer in the child. So the sound's playing. I 'touch
> stop' and the controler signals SIGQUIT to the player child. This works as
> I can see when I catch SIGQUIT there. Still, the SIGQUIT is not forwarded
> to the child running alsaplayer the way it is supposed to do - at least according
> to my literature.
>
> Am I missing something here? Any idea how I could do this differently?
Here's a rewrite of what you had:
sub controller
{
my $pid = fork;
player() unless $pid;
sleep(10) UNTIL -e "stop";
kill 'QUIT', $pid;
}
sub player
{
system("alsaplayer -q song.mp3");
sleep;
}
The subroutine 'player' looks OK, but how about this for 'controller'
sub controller
{
my $pid = fork;
die "Unable to fork" unless defined $pid;
if ( $pid == 0 ) {
player();
} else {
sleep(10) until -e "stop";
kill 'QUIT', $pid;
}
}
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]