[Top][All Lists]

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

Re: Graphics in forked subprocess

From: Pavel Hofman
Subject: Re: Graphics in forked subprocess
Date: Sun, 19 May 2019 21:52:39 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

Hi Mike,

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);

Thanks a lot for your help. I did use exec. But exec creates two child processes: A) octave which runs B) /usr/lib/x86_64-linux-gnu/octave/4.2.2/exec/x86_64-pc-linux-gnu/octave-gui. B) runs the actual script while PID of A) is returned by exec(). I need to have a way to stop the child process from my control script. I wanted to stop the child process by sending kill(pid) - for that I need pid of B) - sending kill to A) does not stop B). I have to be able to check B) has finished/died to restart if needed

That is why I skipped the exec call and sourced octave code directly after forking.

Please what is the best practice for this kind of control? I know I can use a side channel, but I want to be able to kill the child reliably (kill -15 ?) even if it gets stuck.

I could write the control script in shell (bash) but I would love to write a single code for linux and windows, if actually possible. I see Octave for windows uses vbs scripts for startup... perhaps I will have to resort to that too, as the last resort...

Thanks a lot,


reply via email to

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