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

Bruce bbruen at ...2308...
Sun Jan 12 01:53:30 CET 2014


On Sun, 2014-01-12 at 09:39 +1030, Bruce wrote:
> On Tue, 2013-08-13 at 12:15 +0200, Tobias Boege wrote:
> > On Tue, 13 Aug 2013, Beno?t Minisini wrote:
> > > > 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...
> > > 
> > 
> > Besides the syntax, there is another thing to be aware of: If there is a
> > pipe from child -> parent (write -> read) and after the parent dies, the
> > child writes to the pipe, it will receive a SIGPIPE and die, too, if it
> > doesnt't catch this signal.
> > 
> > It means if whatever flag to enable setsid() is set, the user must carefully
> > think about adding For Read/Write/Input/Output.
> > 
> > Regards,
> > Tobi
> 
> Good morning,
> 
> Did this ever get taken further? (Another long post sorry!)
> 
> I now find myself in a similar situation to Tobi, a little simpler but
> with an added twist.
> 
> Basically, we have about 8 projects that can shell each other in a
> certain heirarchy.  Each of these provides functionality based on a
> "log-in role" matching the role that the user wants to assume for that
> session. So a simple example of a hierarchy would be
> manager-->analyst-->tester-->testdeveloper.  That is the manager role
> can shell the analyst role project which can shell the tester role etc.
> There are other more complex heirarchies.
> 
> What I need to provide is two exit strategies, "Quit" and "Quit All"
> that would nicely close down either the current project leaving any
> child processes running or close the current project and all child
> processes respectively. The "twist" is that they want the "Quit All" to
> also close any parent processes, in other words to work both up and down
> the chain at every level. I think these are two different things from
> the Gambas point of view (and on further consideration, lets leave that
> out of this.)
> 
> I thought that the 1) hProc.Ignore=True could provide the "Quit All" for
> the first matter, and I think hProc.Ignore=False might provide the
> "Quit" but it would leave the parent process running which in turn wont
> exit until the remaining child processes exit.  
> 
> Here's the issue:
> Re 1) Since the user could start multiple child processes I use a global
> array $processes of type Process[] and add the hProc every time they
> start a new child. The two handlers for the Quit menu items are:
> 
>         Public Sub mnuExit_Click()
>         
>           Me.Close
>         
>         End
>         
>         Public Sub ExitAll_Click()
>         
>           Dim hProc As Process
>           
>           For Each hProc In $Processes
>             $hProc.Ignore = True
>           Next
>         
>           Me.Close
>         
>         End
> 
> When I run this inside the IDE it all works, no matter how many child
> processes they kick off. ps f -U bb -o pid,ppid,args shows (abridged
> output):
>   PID  PPID COMMAND
> 17447     1 gbr3 /usr/bin/gambas3
> 18411 17447  \_ /usr/bin/gbx3 -g -f 17447 /.../atestmgr/tmmanager
> 18439 18411      \_ gbr3 /.../atestmgr/tmttester/tmttester.gambas
> 18449 18411      \_ gbr3 /.../atestmgr/tmdeveloper/tmdeveloper.gambas
> 18468 18411      \_ gbr3 /.../atestmgr/tmanalyst/tmanalyst.gambas
> 
> and when I "Quit All" from proc 18411 they all close down.
> 
> Now if I run the compiled tmmanager from a vterminal I get:
>   PID  PPID COMMAND
> 17187     1 lxterminal
> 17872 17187  \_ /bin/bash
> 18722 17872      \_ gbr3 ./tmmanager.gambas
> 18739 18722          \_gbr3 /.../atestmgr/tmdeveloper/tmdeveloper.gambas
> 18744 18722          \_ gbr3 /.../atestmgr/tmttester/tmttester.gambas
> 18751 18722          \_ gbr3 /../atestmgr/tmanalyst/tmanalyst.gambas
> 
> as expected, BUT when I "Quit All" (from 18772) the children stay alive:
> 
>   PID  PPID COMMAND
> 18751     1 gbr3 /.../atestmgr/tmanalyst/tmanalyst.gambas
> 18744     1 gbr3 /.../atestmgr/tmttester/tmttester.gambas
> 18739     1 gbr3 /.../atestmgr/tmdeveloper/tmdeveloper.gambas
> 17187     1 lxterminal
> 17872 17187  \_ /bin/bash
> 
> and magically they have moved to the init proc.
> 
> Finally, If I just "Quit" from either the IDE debug mode or from the
> vterminal the expected occurs - the original process stays alive until
> the last child process exits.
> 
> So, it appears gbx3 and gbr3 are doing different things?
> 
> regards
> Bruce
> 
Before you ask, here it is.
B


-------------- next part --------------
A non-text attachment was scrubbed...
Name: multiproc.tar.gz
Type: application/x-compressed-tar
Size: 283325 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20140112/d0bf466d/attachment.bin>


More information about the User mailing list