Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

pipes and forking

redhanzredhanz Posts: 50Member
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

Comments

  • JonathanJonathan Posts: 2,914Member
    : 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.");

Sign In or Register to comment.