RE: SIGINT and SIGQUIT with system()
R. Joseph Newton wrote: [EMAIL PROTECTED] wrote: if (!$pid) { player(); } while (!-e stop) { sleep(10); } kill('QUIT', $pid); ... Am I missing something here? Any idea how I could do this differently? Yes. Braces. They may not be required here--are you using strict?--but they would certainly make more clear to any human reading this code what your intent is. A control statement is meant to control a block of code. The block could be empty, have an empty statement, have a single line, or have a series of stements affecting the flow of tens of thousnads of lines of code. No matter how obvious it seems, marking your execution blocks is worth the effort. What braces are missing? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: SIGINT and SIGQUIT with system()
[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]
SIGINT and SIGQUIT with system()
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); } 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? Thanks for your hints,Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: SIGINT and SIGQUIT with system()
[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. No, I don't think that's correct. A terminal driver will catch ^C and ^\ and send the appropriate signals to all the processes in the foreground process group, but that has nothing to do with system(). 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(); } (Lose the char) Note that after player returns, the child will execute the code below. The child should exit() when it's finished. while (!-e stop) { sleep(10); } kill('QUIT', $pid); Why use SIGQUIT? Do you want the core dump? SIGTERM would be the typical use. Also, $pid is the PID of your child, not the PID of alsaplayer. You kill a process group to send the signal to both, but if you exec() alsaplayer (see below), you don't have to fool with that. perldoc -f kill perldoc -f getpgrp } sub player { system(alsaplayer -q song.mp3); sleep; Why should the child wait here? If it finishes, why not exit? Also, why not just use exec() instead of system()? That would make: sub player { exec 'alsaplayer -q song.mp3' } } 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. I don't think that literature is correct. Am I missing something here? Any idea how I could do this differently? sub controller { defined(my $pid = fork) or die Couldn't fork: $!; exec('alsaplayer -q song.mp3') unless $pid; sleep 1 while !-e 'stop'; kill 'TERM', $pid; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]