help-octave
[Top][All Lists]
Advanced

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

Re: Re: Graphics in forked subprocess


From: Tatsuro MATSUOKA
Subject: Re: Re: Graphics in forked subprocess
Date: Mon, 20 May 2019 19:36:16 +0900 (JST)

--- pavel.hofman
> Hi Mike,
> 
> Dne 19. 05. 19 v 22:53 Mike Miller napsal(a):
> > On Sun, May 19, 2019 at 21:52:39 +0200, Pavel Hofman wrote:
> >> 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().
> > 
> > Are you sure the process IDs of A and B are different? In my testing they 
> > are the same. The intent is for the process ID to remain the
> > same.
> 
> There are two processes for each octave created:
> 
> 4868 pts/4    S+     0:00 octave testExec.m
>  4869 ?        Ssl    0:00
> /usr/lib/x86_64-linux-gnu/octave/4.2.2/exec/x86_64-pc-linux-gnu/octave-gui
> testExec.m
> 
>  4885 ?        S      0:00 octave testGui.m
>  4886 ?        Ssl    0:00
> /usr/lib/x86_64-linux-gnu/octave/4.2.2/exec/x86_64-pc-linux-gnu/octave-gui
> testGui.m
> 
> The fork call returns PID 4885. If testExec does not use waitpid() and
> 4885 gets killed (kill 4885), the child 4886 exits correctly, but 4885
> stays running as zombie process and checking with kill(4885, 0) keeps
> returning 0 - the process is still running.
> 
> I need to start 3 children. The waitpid(-1) should be waiting for any child 
> and return the child PID which finished. Still my controlling thread cannot 
> block, it must be able to react to user requests. My idea was to check for 
> all child PIDs existence with a loop using kill(PID, 0), without blocking 
> with waitpid().
> 
> I could have one  thread blocked with waitpid, restarting the respective 
> children if needed, and another sending the kills if requested by the user.
> 
> But GUI (pushbutton callback) and waitpid do not mix as the GUI callback 
> requires pause/waitfor while waitpid blocks, never reaching that code...
> 
> > 
> >> 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.
> > 
> > That sounds like a fine approach.
> 
> Well, I really do not want to use the side channel as it is not reliable.
> 
> > Keep in mind there is at least one known bug with ending an Octave process 
> > with SIGTERM in Octave 4.4
> > and later versions.
> > 
> > https://savannah.gnu.org/bugs/?54444)
> 
> Interesting, please any chance of that fixed? I do not know if that would 
> affect my case but probably yes - I wanted to be sending sigterm signals.
> 
> Please does this fork/exec/kill functionality work in windows octave build 
> too? If not, no reason to fight this in octave and I whould directly use bash 
> for linux and vbs for windows somehow.
> 
> 
> Thanks a lot,
> 
> Pavel.
> 
> 
windows itself does not have fork and octave for native windows does not have 
fork.

If you want fork on windows, try cygwin or wsl.

Tatsuro



reply via email to

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