Re: g_spawn_async lockup



Hi,

Some days ago I posted this problem, no reaction yet.
Can anybody comment on it? Is the problem clear?

A small refrase:

g_spawn_async_with_pipes starts an external program.
This program generates data on stdout.
The function attached to g_child_watch_add does do the postprocessing.

The problem is that due to pipe-filling the program halts, so postprocessor isn't started, as a result a 
lockup.


The relevant code:

Main:
(with argv[0]=program, argv[1]... its arguments) 
g_spawn_async_with_pipes(NULL,argv,NULL,
                         G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH,
                         NULL,NULL,&pid,NULL,
                         &fd,NULL,NULL);
g_child_watch_add(pid,(GChildWatchFunc)post_process,(gpointer)fd);


The postprocessing:

static void post_process(GPid pid,int status,gpointer data)
{
  int fd=(int)data;

  if (fd)
  {
    while ((read(fd,&b,1)))
    {
...
    }
    close(fd);
  }
}

This locks up if the amount of data exceeds a certain limit.


Alternative: Redirect output to a file, do postprocessing on that.

Relevant code:

(with argv[..]=program > output_file)   
g_spawn_async(NULL,argv,NULL,G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH,NULL,NULL,&pid,NULL);
g_child_watch_add(pid,(GChildWatchFunc)post_process,data);



This doesn't seem to work: a program redirecting to a file used with
g_spawn_async.

Any idea to solve this problem, either with or without piping?

Regards,
Rob A.



Rob Alblas wrote:
Hi,
I want to execute an external program using g_spawn_async_with_pipes.
This program outputs ASCII to stdout, which I want to catch using
g_child_watch_add.
This works fine, but if the data exceeds a certain amount of data
apparently the pipe gets 'full', causing the ext. program to wait with
outputting.
As a result the g_child_watch_add will not start reading the pipe.

So g_child_watch_add waits until the ext. program is finished and the
ext. program waits until g_child_watch_add starts with reading from the
pipe.

How to deal with this?

I tried to redirect the output to a file, and use g_spawn_async instead
of g_spawn_async_with_pipes, but redirecting seems not to be accepted by
g_spawn_async.

(For this second method I tried flags G_SPAWN_FILE_AND_ARGV_ZERO and
|G_SPAWN_STDOUT_TO_DEV_NULL, without success.)
|

Rob A.



  

-- 
This message has been scanned for viruses and is believed to be clean




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]