Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
pipes and forking Posted by redhanz on 10 Oct 2004 at 1:34 PM
i am programming in ruby but its kinda similar to perl.

i can write the maximum amount to a pipe in a child process by a continual loop. Once the pipe is full, it goes back to the parent process where it waits. I want to exit the program once the pipe is full? Ani ideas as to how:
here is my psuedo ruby code

rd, wr = my read pipes and write pipes

if fork{
/*parent*/
Process.wait

}

else
/*child*/
loop{
write to pipe
count++ /*store the size of pipe*/
}

so once the pipe is full, it wont let me write to it and i go back up to the parent process and wait indefinetly. Any suggestions?
thnx
redhanz

Report
Re: pipes and forking Posted by Jonathan on 13 Oct 2004 at 4:23 AM
: i am programming in ruby but its kinda similar to perl.
:
Hmmm...I once read somewhere that Perl programmers who switch to Ruby explode. But anyway...

: i can write the maximum amount to a pipe in a child process by a continual loop. Once the pipe is full, it goes back to the parent process where it waits. I want to exit the program once the pipe is full? Ani ideas as to how:
: here is my psuedo ruby code
:
: rd, wr = my read pipes and write pipes
:
: if fork{
: /*parent*/
: Process.wait
:
: }
:
: else
: /*child*/
: loop{
: write to pipe
: count++ /*store the size of pipe*/
: }
:
: so once the pipe is full, it wont let me write to it and i go back up to the parent process and wait indefinetly. Any suggestions?
: thnx
: redhanz
:
Put your write call in an if block, check for write to fail (in Perl an unless block would be the most readable choice instead of an if one) and then if it does fail, you know the pipe is full so call exit in the child process, which will terminate that process. The parent, then having nothing else to do ('cus it was waiting for the child to terminate) will also exit.

I *think* that will do it.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.