[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] popen i read/write mode



Peter Makholm <sslug@sslug> wrote:

>   if (fork) {
>     dup2(stdin[1],0);
>     dup2(stdout[1],1);
>     dup2(stderr[1],2);
>     
>     execvp(file,argv);
>   }

I praksis bliver man i det generelle tilfælde mig bekendt nødt til at
fork()'e to processer. Den ene proces kører programmet som ovenfor,
den anden sender data til programmet. Den oprindelige proces kan så
læse resultatet fra programmet.


Jeg formulerede engang problemet i news:dk.edb.programmering.c som:

Hvis A og B er forbundet med to pipes, 

   A  --0->  B
   A  <-1--  B

hvordan sikrer man sig så at de samtidige kald

   A: write(0, mem, stor);
   B: write(1, mem, stor); 

ikke hænger fordi begge processer venter på at den anden proces får
tømt pipen (hvis buffer antages at være mindre end værdien af "stor") ?



Anders.

PS. Et alternativ er at gøre skrivningen ikke-blokerende. Et andet er
at vide nok om det kørte program til, at problemsituationen ikke opstår.


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *