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

Re: Howto update $statusbar from fork() proces



On Mon, 23 Aug 1999 22:43:44 +0200, luc Arits wrote:
> I'm writing a program in Perl/gtk and an wondering how to update a,statusbar
> integrated in the Gui while downloading multiple files from the net in a
> forked proces.

Simple answer: you can't. More complicated answer: you can.

You can't because only a single process is allowed to update the windows.
Your program will crash if you try to do it from others (hint: the X
server has one window with several programs attached, to which should it
listen?).

What you can do is making a pipe or a shared memory segment between the
two processes. The child writes to the pipe (or shm segment) what it is
doing, the parent reads it and updates the progress bar. Example fork+pipe
code is in DOSemu (www.dosemu.org), look for file dos2unix.c (IIRC). Or
buy/lend/steal a copy of "Advanced programming in the Unix environment" by
Richard Stevens.

> I want to see what pages I'm downloading.
> Something like (just example code);
> 
> use LWP::Simple;
> my $pid
> if ($pid=fork())
> { 
>     foreach $url (@urls) 
>         {
>          $page=get ($url);
>         $statusbar->push(1, "downloading $url");
>          }
>     exit(1);
> }

Hmm, your fork code is not correct, the parent does the downloading, not
the child! Have a look at the GTK+ FAQ, there is some fork() example code
(in C, but you can port it to Perl). Also have a look at the fork manpage.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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