[Gambas-user] Starting a Process and forgetting about it

Benoît Minisini gambas at ...1...
Tue Aug 13 11:31:19 CEST 2013


Le 13/08/2013 11:22, Tobias Boege a écrit :
> On Tue, 13 Aug 2013, Beno?t Minisini wrote:
>> Le 07/08/2013 10:08, Tobias Boege a ?crit :
>>> Hi,
>>>
>>> in a project I need to start a server Process and watch its Kill event while
>>> the program is running. The server shall, however, continue to run even
>>> after my program exits.
>>>
>>> I'm kind of stuck here: If I create a Process, Gambas keeps watching it and
>>> doesn't shutdown the program until the process dies. Can I somehow tell
>>> Gambas to forget about that Process and just exit?
>>>
>>> I have used the Quit instruction until a minute ago (without any errors or
>>> complaints) to get the program down ultimately but as I know this is a Bad
>>> Idea: here's my mail.
>>>
>>> Now I'm working around this problem like that: I use the Shell instruction
>>> to start a shell as the child process Gambas watches. I can safely kill the
>>> shell which makes Gambas happy and reparents the server to init which is
>>> also fine. I have either to document this workaround because IMHO it's quite
>>> subtle or have an explicit way of having Gambas forget about a Process...
>>>
>>> Regards,
>>> Tobi
>>>
>>
>> I added the Process.Ignore() method in revision #5791 for that. Tell me
>> if it works for you.
>>
>
> The commit log tells that the process is automatically killed (not waited
> for) when the Gambas program exits. This is not what I needed. It would be a
> shorthand for something like this in the startup class:
>
> ---
> Private $hProcess As Process
>
> Public Sub Form_Close()
>    Try $hProcess.Kill()
> End
>
> Public Sub btnStartProcess_Click()
>    $hProcess = Shell "..." As "Process"
> End
> ---
>
> because you don't need to save the Process object anymore to have it killed.
> You could now do:
>
> ---
> Public Sub btnStartProcess_Click()
>    Dim hProcess As Process
>
>    hProcess = Shell "..." As "Process"
>    hProcess.Ignore()
> End
>
> ' Use Last in any "Process" events
> ---
>
> Right? What I wanted to do is run a child process and if the Gambas program
> exits, do nothing about the process and let init adopt it (the child shall
> continue to run).
>
> However, I don't think this is a common enough scenario to have it
> implemented directly in the Process object. I got by by using Shell
> "setsid ... &". Whereas automatically killing background child processes
> seems to be a nice addition. Thanks for your effort anyway.
>
> Regards,
> Tobi
>

I could call setsid() for the child process, but I have no syntax in the 
EXEC/SHELL instruction for that. I will think about it...

-- 
Benoît Minisini




More information about the User mailing list