Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^5: To organize pipe right way.

by kennethk (Abbot)
on May 06, 2016 at 17:28 UTC ( [id://1162369]=note: print w/replies, xml ) Need Help??


in reply to Re^4: To organize pipe right way.
in thread To organize pipe right way.

use warnings; use strict;
Your posted code does not pass strict. This tells me you are not posting the same code you are running. The confusion on this thread is largely driven by not being able to reach mutual understanding of issues. See How do I post a question effectively?. Do not include strict if you don't use it, and don't post code that doesn't compile.
if( $nomer_vosproizvodyshchego_protsessu=fork ){
This does not consider the possibility that the fork has returned undef, i.e., has failed. It also means you need to have the rest of your code, none of which is shared, indented into if blocks. That's why I keep using the
my $pid = fork(); die "Fork failed\n" unless defined $pid; if ($pid == 0) { $| = 1; exec @args; }
motif.
# Same thing? -- I.e. not working? $|=1; $FIFO->autoflush( 1 );
Not the same thing. $| only affects the current active file handle, as controlled by select and by default STDOUT.
print $FIFO 'pause';
Are you sure that shouldn't be print $FIFO "pause\n";
for( $i=0; $i<=$#svitok_na_vosproizvedenie; $i++ ){ system( '/usr/bin/mplayer -slave -input file='.$svitok_truby.' '.$ +svitok_na_vosproizvedenie_kom[$i] ); }
So you are opening more than one instance of mplayer? I guess this is supposed to be a playlist. Using a blocking call to system to control playing makes sense; the exec solution here would require monitoring the child for an exit status prior to spawning another child, which has an unnecessary number of moving parts. I think your call would be cleaner with interpolating double quotes, but that's cosmetic. system("/usr/bin/mplayer -slave -input file=$svitok_truby $svitok_na_vosproizvedenie_kom[$i]");
unlink $svitok_truby;
The reason I wrapped this in an END block was so that it would always execute, even when the script dies. You never want the file lying around afterward.

Finally, have you tried the example cases I gave you? Have you tried isolating where the lag could be? Rather than worrying about all the other stuff, just try looping over a pause:

#!/usr/bin/perl use strict; use warnings; use POSIX qw( mkfifo ); use IO::Handle; my $svitok_truby = 'tmp.pp'; mkfifo( $svitok_truby, 0700 ) || die "Pipe fail; $svitok_truby : $!" +; local $SIG{CHLD} = "IGNORE"; my @args = ('/usr/bin/mplayer', '-slave', '-input', "file=$svitok_trub +y", '/tmp/1.flac'); my $pid = fork(); die "Fork failed\n" unless defined $pid; if ($pid == 0) { exec @args; } open (my $FIFO, '>', $svitok_truby) || die "can't open $svitok_truby: + $!"; $FIFO->autoflush(1); for my $i (1 .. 10) { print $FIFO 'pause'; sleep 1; } print $FIFO 'quit'; close($FIFO); END { unlink $svitok_truby; }

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^6: To organize pipe right way.
by nikolay (Beadle) on May 07, 2016 at 12:08 UTC

    The code has other parts where variables are declared, that's why the posted code is not compiled w/ strict. Actually, i did not mean you will compile it, but rather a look and give me your feedback on possible reason of such pipe behaviour. So, do not look at the strict, or include in the file before your compilation. I publish code pieces as they are, basicly, because of «use POSIX qw( mkfifo )».

    Seems to me that using «$|=1» is redundant here. By design, «$FIFO» has to do all the stuff OR «$|» w/o using «IO» module.

    Also no need for «\n» in «print $FIFO 'pause'» becuse it works as bad as without it.

    I did run your script and pause did not work a single time!

      Finally, i have guessed how i did forking so that if flawlessly worked. But that part was done together w/ BaSh -- so no interest for the question in PERL here, I tried hard w/ PERL to do forking the way i wanted -- but gave up w/ PERL, in favour of BaSh.

      Thank you for all, who participated! I close my question here.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-25 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found