[Top][All Lists]

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

Re: Graphics in forked subprocess

From: Mike Miller
Subject: Re: Graphics in forked subprocess
Date: Sun, 19 May 2019 12:26:24 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

On Sun, May 19, 2019 at 21:04:50 +0200, Pavel Hofman wrote:
> Hi,
> I am trying to write a control script for my set of octave scripts which
> must run simultaneously. I am trying to use fork/exec.
> testGui.m:
> figure();
> while true
>   pause(1);
>   printf('Paused\n');
> endwhile
> testFork.m:
> ctrlPid = ( @() fork() )();
> if ctrlPid == 0
>   source('testGui.m');
> else
>   waitpid(-1);
> endif
> When running testGui directly from terminal, it shows the figure correctly:
> octave testGui.m
> But when running testFork, the figure never appears while Paused get printed
> out - the process testGui.m is clearly running.
> octave testFork.m
> This problem is under Linux/Ubuntu, older octave 4.2.2. Is perhaps this
> issue solved by in Octave 5.1?

No, the issue is that your script is using 'fork' without 'exec'. You
mention 'exec', but it doesn't appear in the above.

It's a well known problem that "fork without exec" does not work with
large libraries and frameworks linked with a program, including Python,
Qt, probably Java. In fact, it's considered deprecated on macOS now to
'fork' a process and not 'exec' a brand new executable image.

Calling 'fork' by itself for creating worker child processes should only
be used carefully in small programs that don't link with large
frameworks, such as Octave.

Can you rework your scripts so that 'fork' is followed immediately by
'exec' to start a new separate Octave process for example?

    ctrl_pid = fork ();
    if (ctrl_pid == 0)
      exec ('octave', 'testGui.m');
      waitpid (ctrl_pid);


Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]