Blocking with pipes.

Blocking with pipes.

Post by Andrew Ver » Sun, 29 Sep 1996 04:00:00



In a program that I am trying to write, I have

switch(fork()) {
case 0:
        dup2(fd[1],STDOUT_FILENO);
        dup2(fd[0],STDIN_FILENO);
        close(fd[1]);
        close(fd[0]);
        execvp(argv[0],argv);
        perror("BLA");
        exit(0);
default:
        write(fd[1],buffer,counter);
        close(fd[1]);

        while(read(fd[0],string,50) > 0 ) {
                do something with string;
        }
        close(fd[0]);
        break;

Quote:}

Why does this read some of the input from the executing file and then
hang (block) ?
 
 
 

Blocking with pipes.

Post by J Wuns » Mon, 30 Sep 1996 04:00:00



>    while(read(fd[0],string,50) > 0 ) {
>            do something with string;
>    }
> Why does this read some of the input from the executing file and then
> hang (block) ?

I can't get it to work either.  It works when using two pipes,
however.  I think your called application gets confused that stdin and
stdout do refer to the same object.  Well, not sure, just a wild
guess...

--
cheers, J"org


Never trust an operating system you don't have sources for. ;-)

 
 
 

Blocking with pipes.

Post by Terry Lamber » Mon, 30 Sep 1996 04:00:00


]         while(read(fd[0],string,50) > 0 ) {
]                 do something with string;
]         }

[ ... ]

] Why does this read some of the input from the executing file
] and then hang (block) ?

Because you use stdio in the writer program, and output is not
flushed automatically?

Note: if you are using gets()/etc. to read to imply a flush,
you should be aware that implie flush only functions on tty
devices, not pipes (see the man page, see POSIX, see ANSI).

                                        Terry Lambert

---
Any opinions in this posting are my own and not those of my present
or previous employers.

 
 
 

Blocking with pipes.

Post by Brian Some » Tue, 01 Oct 1996 04:00:00


: In a program that I am trying to write, I have

: switch(fork()) {
: case 0:
:       dup2(fd[1],STDOUT_FILENO);
:       dup2(fd[0],STDIN_FILENO);
:       close(fd[1]);
:       close(fd[0]);
:       execvp(argv[0],argv);
:       perror("BLA");
:       exit(0);
: default:
:       write(fd[1],buffer,counter);
:       close(fd[1]);
:      
:       while(read(fd[0],string,50) > 0 ) {
:               do something with string;
:       }
:       close(fd[0]);
:       break;
: }

: Why does this read some of the input from the executing file and then
: hang (block) ?

What does the executing program do ?  You've set up a scenario where the
above program writes "buffer" to the pipe, then reads it again !  At
the same time, you've got argv[0] running - also potentially both reading
and writing from/to the same pipe.

When you run this sort of thing, the first line the above "read" sees is
whatever buffer contains - it's read back immediately.  If you're lucky
however, your "executed program" may manage to read it first - or even
write something first so that the above read can read that something
before seeing "buffer" - or maybe it'll never see "buffer" 'cos argv[0]
gets it....

The scenario is silly - it's just a pile of race conditions.

--

Don't _EVER_ lose your sense of humour....

 
 
 

Blocking with pipes.

Post by BL » Tue, 08 Oct 1996 04:00:00


Curious, what is this account used for?

TIA,

-----|||--------------------------------+-------------------------------

 |||\||| Newbridge Networks Corp.       | phone : +1 613 591-3600
 |||\\|| 600 March Road, P.O. Box 13600 | fax   : +1 613 591-3680
 |||\\\| Kanata,  Ont.  Canada K2K 2E6  |
-|||------------------------------------+-------------------------------

 
 
 

Blocking with pipes.

Post by Don Yunisk » Thu, 10 Oct 1996 04:00:00




>Curious, what is this account used for?

toor == root spelled backwards!  :>
 
 
 

Blocking with pipes.

Post by Clint Wolf » Thu, 10 Oct 1996 04:00:00


;


; >Curious, what is this account used for?
;
; toor == root spelled backwards!  :>

For those backward people that still use Bourne shell... (/bin/sh)

--
Underscores added to return address to defeat advertising engines.


 
 
 

Blocking with pipes.

Post by Brian Some » Thu, 10 Oct 1996 04:00:00




Quote:> Curious, what is this account used for?

It's a user-friendly root account.  One that uses "bash" instead of "csh".

Curious, how come you posted this as a followup to a programming question ?

--

      <http://www.awfulhak.demon.co.uk/>
Don't _EVER_ lose your sense of humour....

 
 
 

Blocking with pipes.

Post by Matthew Dill » Sun, 13 Oct 1996 04:00:00





:>> Curious, what is this account used for?
:>>
:>
:>It's a user-friendly root account.  One that uses "bash" instead of "csh".
:>
:>Curious, how come you posted this as a followup to a programming question ?
:>
:>--

:>      <http://www.awfulhak.demon.co.uk/>
:>Don't _EVER_ lose your sense of humour....

    I've always used it as a backup-csh account myself, so I could
    install a (shared library) tcsh as the main root shell.

                                                -Matt

--
    Matthew Dillon   Engineering, BEST Internet Communications, Inc.

    [always include a portion of the original email in any response!]

 
 
 

1. Non Blocking Named Pipe

I am trying to write an Ansi C program to write to a named pipe in
non-blocking mode.  When I try to do a write I get a return of -1, and the
data does not get into the pipe.  Does anyone have any advice on coding a
Non-Blocking Pipe routine.  My criteria is that I wish to write to the Pipe
even if the routine to read the pipe has been terminated for some reason.

I'd appreciate any help you can offer.

David Howells.

2. Spanning file systems across multiple disks

3. Blocking on pipes.

4. Booting Solaris "Read-Only"...?

5. Does fread() block on piped streams?

6. User login's

7. select() and write() behavior with non-blocking named-pipe

8. New Java Desktop, any BETA testers want to comment

9. dump pipe gzip pipe ssh pipe dd... blocksize?

10. Non blocking socket blocks; says 'read would block' ?

11. Blocking on a pipe

12. Closing a blocked pipe, can I kill the process?

13. ksh as coprocess, want blocking pipe.