Unix/X11 child process progress dialog

Unix/X11 child process progress dialog

Post by William Robert Cav » Tue, 13 Aug 1996 04:00:00



Hi,

I am trying to use the Free Widget Foundation PcBar progress indicator
widget, in a motif message dialog box, to indicate the progress of a
potentially lengthy operation, run as a child process of my main
application.

The attached source code shows how i have tried to implement this and
works to a point. The dialog box is realised and the process
successfully forks and execs, however the required update to the
percentage bar widget does not happen until the child process
terminates, at which point the indicator leaps from 0% to 100%.

The actual child process takes in excess of one minute to execute and so
i think i can rule out delays in window mapping. Also if i place an
XFlush() command after each update percentage widget call, there is
still no improvement.

The code is very much a first attempt and consequently there is no error
checking for child/parent UNIX signals, etc.

Any suggestions would be deeply appreciated.

Cheers.....

William

[ PcBarM.c 3K ]
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/PushB.h>
#include <Xm/MessageB.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "/users/wrc1/FWF/src/PcBar/PcBar.h"

#define REQ_COLOUR (Pixel)3
#define MAX_FILE_VALUE 94.0

static int pcval;
static Widget PcBar;

Widget CreatePCDoneDialog(Widget);
void PcBarCB ( Widget, XtPointer,XtPointer);

int main ( int argc, char **argv )
{
    Widget       shell, button;
    XtAppContext app;
    char *prgname={"/users/wrc1/rp/sarhp"};

    shell = XtAppInitialize ( &app, "Askquestion", NULL, 0,
                              &argc, argv, NULL, NULL, 0 );

    button = XtCreateManagedWidget ( "Quit",
                                     xmPushButtonWidgetClass,
                                     shell, NULL, 0 );

    XtAddCallback(button, XmNactivateCallback, PcBarCB, (XtPointer)prgname);                          

    XtRealizeWidget ( shell );
    XtAppMainLoop ( app );
    return(0);

}

Widget CreatePCDoneDialog(Widget w)
{
        static Widget retw=NULL;
         Widget form;

         if (retw==NULL)
         {      
                retw = XmCreateMessageDialog ( w, "PcBarM", NULL, 0 );
                XtVaSetValues ( retw,
                                                        XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
                                                NULL );

                form = XtCreateManagedWidget("form",xmFormWidgetClass,retw,NULL,0);
                PcBar =    XtVaCreateManagedWidget("testpc", xfwfPcBarWidgetClass, form,
                                                                                        XtNshowzero, True,
                                                                                        XtNforeground, REQ_COLOUR,
                                                                                        XtNdisplaypc,True,
                                                                                        XmNtopAttachment, XmATTACH_FORM,
                                                                                        XmNbottomAttachment, XmATTACH_FORM,
                                                                                        XmNleftAttachment,XmATTACH_FORM,
                                                                                        XmNrightAttachment,XmATTACH_FORM,
                                                                                        NULL);

        }
        return(retw);

}

void PcBarCB ( Widget    w,
                          XtPointer clientData,
                          XtPointer callData )
{
        Widget dialog;
        int i;
        int fd[2],result,cnt=0;
        pid_t pid;
        char line[51],c;
        char *prgname=(char*)clientData;

        dialog = CreatePCDoneDialog(w);
        XtManageChild ( dialog );

        if (pipe(fd) < 0) { fprintf(stderr,"Duff  pipe formation\n"); exit(-1); }

        if ( (pid = fork()) < 0)
        {
                fprintf(stderr,"Fork error\n");
        }
        else if (pid > 0)    /* PARENT code */
        {
                close(fd[1]);           /* close parent write pipe */
                while (read(fd[0],&c,1) != NULL)
                {
                        switch(c)
                        {
                                case '0': case '1': case '2': case '3': case '4': case '5':
                                case '6': case '7': case '8': case '9':
                                        line[cnt] = c;
                                        cnt++;
                                        break;
                                default:
                                                if (cnt)
                                                {
                                                        line[cnt] = 0;
                                                        cnt=0;
                                                        sscanf(line,"%d",&result);
                                                        result = (result/MAX_FILE_VALUE)*100;
                                                        XfwfPcBarSetPercentage(PcBar, result);
                                                }
                                                else cnt = 0;
                                                break;
                        }
                }
        }
        else                    /* CHILD code */
        {
                close(fd[0]);           /* close childs read pipe */
                if (fd[1] != STDOUT_FILENO)
                {
                        if (dup2(fd[1],STDOUT_FILENO) != STDOUT_FILENO) fprintf(stderr,"Duplication Error\n");
                        close(fd[1]);   /* Not needed after dup */
                }              

                if (execl(prgname,"sarhp",(char*)0) < 0) fprintf(stderr,"DUFF EXEC\n");
        }

}

 
 
 

Unix/X11 child process progress dialog

Post by Stephen Bayn » Wed, 14 Aug 1996 04:00:00



: This is a multi-part message in MIME format.
Troublemaker :-)

: --------------76342B9D192C
: Content-Type: text/plain; charset=us-ascii
: Content-Transfer-Encoding: 7bit

: Hi,

: I am trying to use the Free Widget Foundation PcBar progress indicator
: widget, in a motif message dialog box, to indicate the progress of a
: potentially lengthy operation, run as a child process of my main
: application.

: The attached source code shows how i have tried to implement this and
: works to a point. The dialog box is realised and the process
: successfully forks and execs, however the required update to the
: percentage bar widget does not happen until the child process
: terminates, at which point the indicator leaps from 0% to 100%.

I have not time to read your source in detail, it looks to me if you are
reading the childs output from a pipe to monitor the childs progress.
The problem imay be that the child is buffering its output when it
is outputting to a pipe (normal C io library behaviour).
A quick test would be to print out the output from the child as you
receive it.

--

Philips Semiconductors Ltd
Southampton                                 My views are my own.
United Kingdom
 Are you using ISO8859-1? Do you see ? as copyright, as division and ? as 1/2?

 
 
 

Unix/X11 child process progress dialog

Post by K. Joshua Spurgeo » Thu, 15 Aug 1996 04:00:00



> Hi,

> I am trying to use the Free Widget Foundation PcBar progress indicator
> widget, in a motif message dialog box, to indicate the progress of a
> potentially lengthy operation, run as a child process of my main
> application.

Are you sure that your child process is flushing the
pipe after each write onto the pipe. This could be the
reason. Check it.

K.Joshua Spurgeon

 
 
 

1. child process under unix/X11

Hi....Could someone point me in the right direction with the following
problem!

I have an Xwindows/Motif1.2 program from which i would like to run
a seperate executable program. This secondary program is quite
computationally intensive and (possibly) time consuming (it is a
particle tracking/oil spill model). I would like to launch this child
process from a dialog and allow the process to continue in the
background whilst the user is able to return to the parent program.
However I would like to detect termination of the child process, so that
results can then be displayed automatically in my parent program.

To date I have tried using system(), however this seems to run under the
parent process and results in a time consuming wait for results. I have
looked at some rather sketchy notes on using fork() and wait(), but
again this appears to act in the foreground.

No information is exchanged between the programs by pipes,etc so that i
really only want to detect a termination of child process signal.

Any ideas......

Cheers....William

P.S. Any idea where the FAQ is located................?

2. networking problem suse linux 6.3

3. smail failed to reap child process: No child processes

4. ksh - question

5. Getting a child and child's child process-id

6. Sparc 1000 and Volume Manager

7. how to kill a child process that runs other children processes

8. Weird problem with PURIFY on SUNOS

9. Getting a child and child's child process-id

10. child process, child program

11. How to create memory in ptraced child process w/o child source code

12. kill child and its all grad child processes?

13. how do i wait for child processes, and *their* children to finish