SPAWN background command without nohup? [message #88861] |
Sat, 28 June 2014 08:27  |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
Dear Folks,
Using SPAWN to start a background process on unix-like systems
can leave the process running even after the IDL process terminates.
I'd like to arrange things so that the child process is killed when IDL exits.
Here's a schematic example:
IDL> spawn, 'myprocess &', pid=pid
IDL> print, pid
62417
IDL> exit
$ ps | grep 62417
grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
This is similar to running a shell command with nohup:
$ nohup myprocess &
$ exit
Is there a way to make IDL spawn a child process that terminates when
the parent IDL session terminates?
All the best,
David
|
|
|
Re: SPAWN background command without nohup? [message #88866 is a reply to message #88861] |
Mon, 30 June 2014 02:34   |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On Saturday, June 28, 2014 5:27:48 PM UTC+2, David Grier wrote:
> Dear Folks,
>
>
>
> Using SPAWN to start a background process on unix-like systems
>
> can leave the process running even after the IDL process terminates.
>
> I'd like to arrange things so that the child process is killed when IDL exits.
>
>
>
> Here's a schematic example:
>
>
>
> IDL> spawn, 'myprocess &', pid=pid
>
> IDL> print, pid
>
> 62417
>
> IDL> exit
>
>
>
> $ ps | grep 62417
>
> grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
>
>
>
> This is similar to running a shell command with nohup:
>
> $ nohup myprocess &
>
> $ exit
>
>
>
> Is there a way to make IDL spawn a child process that terminates when
>
> the parent IDL session terminates?
>
>
>
> All the best,
>
>
>
> David
You might try to keep your spawned process synchronized with the parent IDL session : maybe by using the UNIT keyword ?
Just a guess, I have no experience with unix.
alx.
|
|
|
Re: SPAWN background command without nohup? [message #88867 is a reply to message #88866] |
Mon, 30 June 2014 03:03   |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
On Monday, June 30, 2014 5:34:13 AM UTC-4, alx wrote:
> On Saturday, June 28, 2014 5:27:48 PM UTC+2, David Grier wrote:
>
>> Dear Folks,
>
>>
>
>>
>
>>
>
>> Using SPAWN to start a background process on unix-like systems
>
>>
>
>> can leave the process running even after the IDL process terminates.
>
>>
>
>> I'd like to arrange things so that the child process is killed when IDL exits.
>
>>
>
>>
>
>>
>
>> Here's a schematic example:
>
>>
>
>>
>
>>
>
>> IDL> spawn, 'myprocess &', pid=pid
>
>>
>
>> IDL> print, pid
>
>>
>
>> 62417
>
>>
>
>> IDL> exit
>
>>
>
>>
>
>>
>
>> $ ps | grep 62417
>
>>
>
>> grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
>
>>
>
>>
>
>>
>
>> This is similar to running a shell command with nohup:
>
>>
>
>> $ nohup myprocess &
>
>>
>
>> $ exit
>
>>
>
>>
>
>>
>
>> Is there a way to make IDL spawn a child process that terminates when
>
>>
>
>> the parent IDL session terminates?
>
>>
>
>>
>
>>
>
>> All the best,
>
>>
>
>>
>
>>
>
>> David
>
>
>
> You might try to keep your spawned process synchronized with the parent IDL session : maybe by using the UNIT keyword ?
>
> Just a guess, I have no experience with unix.
>
> alx.
Thanks for thinking about this.
Using the UNIT keyword is indeed useful for shutting down the child process from the parent IDL session. It doesn't help, however, if the user exits IDL without actively shutting down the
child process.
I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
the parent IDL session ends.
All the best,
David
|
|
|
Re: SPAWN background command without nohup? [message #88869 is a reply to message #88867] |
Mon, 30 June 2014 04:17   |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On Monday, June 30, 2014 12:03:04 PM UTC+2, David Grier wrote:
> On Monday, June 30, 2014 5:34:13 AM UTC-4, alx wrote:
>
>> On Saturday, June 28, 2014 5:27:48 PM UTC+2, David Grier wrote:
>
>>
>
>>> Dear Folks,
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Using SPAWN to start a background process on unix-like systems
>
>>
>
>>>
>
>>
>
>>> can leave the process running even after the IDL process terminates.
>
>>
>
>>>
>
>>
>
>>> I'd like to arrange things so that the child process is killed when IDL exits.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Here's a schematic example:
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> IDL> spawn, 'myprocess &', pid=pid
>
>>
>
>>>
>
>>
>
>>> IDL> print, pid
>
>>
>
>>>
>
>>
>
>>> 62417
>
>>
>
>>>
>
>>
>
>>> IDL> exit
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> $ ps | grep 62417
>
>>
>
>>>
>
>>
>
>>> grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> This is similar to running a shell command with nohup:
>
>>
>
>>>
>
>>
>
>>> $ nohup myprocess &
>
>>
>
>>>
>
>>
>
>>> $ exit
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Is there a way to make IDL spawn a child process that terminates when
>
>>
>
>>>
>
>>
>
>>> the parent IDL session terminates?
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> All the best,
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> David
>
>>
>
>>
>
>>
>
>> You might try to keep your spawned process synchronized with the parent IDL session : maybe by using the UNIT keyword ?
>
>>
>
>> Just a guess, I have no experience with unix.
>
>>
>
>> alx.
>
>
>
> Thanks for thinking about this.
>
>
>
> Using the UNIT keyword is indeed useful for shutting down the child process from the parent IDL session. It doesn't help, however, if the user exits IDL without actively shutting down the
>
> child process.
>
>
>
> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
>
> the parent IDL session ends.
>
>
>
> All the best,
>
>
>
> David
> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
Maybe by using some shared object ? A semaphore or a global memory region. But you would have to modify your child process accordingly.
alx.
|
|
|
Re: SPAWN background command without nohup? [message #88870 is a reply to message #88869] |
Mon, 30 June 2014 05:06   |
dg86
Messages: 118 Registered: September 2012
|
Senior Member |
|
|
On Monday, June 30, 2014 7:17:02 AM UTC-4, alx wrote:
> On Monday, June 30, 2014 12:03:04 PM UTC+2, David Grier wrote:
>
>> On Monday, June 30, 2014 5:34:13 AM UTC-4, alx wrote:
>
>>
>
>>> On Saturday, June 28, 2014 5:27:48 PM UTC+2, David Grier wrote:
>
>>
>
>>>
>
>>
>
>>>> Dear Folks,
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> Using SPAWN to start a background process on unix-like systems
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> can leave the process running even after the IDL process terminates.
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> I'd like to arrange things so that the child process is killed when IDL exits.
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> Here's a schematic example:
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> IDL> spawn, 'myprocess &', pid=pid
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> IDL> print, pid
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> 62417
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> IDL> exit
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> $ ps | grep 62417
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> This is similar to running a shell command with nohup:
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> $ nohup myprocess &
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> $ exit
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> Is there a way to make IDL spawn a child process that terminates when
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> the parent IDL session terminates?
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> All the best,
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> David
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> You might try to keep your spawned process synchronized with the parent IDL session : maybe by using the UNIT keyword ?
>
>>
>
>>>
>
>>
>
>>> Just a guess, I have no experience with unix.
>
>>
>
>>>
>
>>
>
>>> alx.
>
>>
>
>>
>
>>
>
>> Thanks for thinking about this.
>
>>
>
>>
>
>>
>
>> Using the UNIT keyword is indeed useful for shutting down the child process from the parent IDL session. It doesn't help, however, if the user exits IDL without actively shutting down the
>
>>
>
>> child process.
>
>>
>
>>
>
>>
>
>> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
>
>>
>
>> the parent IDL session ends.
>
>>
>
>>
>
>>
>
>> All the best,
>
>>
>
>>
>
>>
>
>> David
>
>
>
>
>
>> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
>
> Maybe by using some shared object ? A semaphore or a global memory region. But you would have to modify your child process accordingly.
>
> alx.
This is a good suggestion. Unfortunately, I'm SPAWNing a precompiled executable: mencoder from the mplayer distribution.
This issue comes up for me because IDL does not invoke the CleanUp method on objects when
it exits. I _could_ write a replacement for EXIT that cleans up objects, but that still would leave open
the possibility that the user could invoke the normal exit command and leave orphaned child
processes running. Unfortunately, IDL does not have anything equivalent to the IDL_STARTUP
mechanism for handling housekeeping during shutdown.
I'm targeting unix-like systems, but would be interested in Windows solutions as well.
All the best,
David
|
|
|
|
Re: SPAWN background command without nohup? [message #88875 is a reply to message #88870] |
Mon, 30 June 2014 09:21  |
lecacheux.alain
Messages: 325 Registered: January 2008
|
Senior Member |
|
|
On Monday, June 30, 2014 2:06:48 PM UTC+2, David Grier wrote:
> On Monday, June 30, 2014 7:17:02 AM UTC-4, alx wrote:
>
>> On Monday, June 30, 2014 12:03:04 PM UTC+2, David Grier wrote:
>
>>
>
>>> On Monday, June 30, 2014 5:34:13 AM UTC-4, alx wrote:
>
>>
>
>>>
>
>>
>
>>>> On Saturday, June 28, 2014 5:27:48 PM UTC+2, David Grier wrote:
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > Dear Folks,
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > Using SPAWN to start a background process on unix-like systems
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > can leave the process running even after the IDL process terminates.
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > I'd like to arrange things so that the child process is killed when IDL exits.
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > Here's a schematic example:
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > IDL> spawn, 'myprocess &', pid=pid
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > IDL> print, pid
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > 62417
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > IDL> exit
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > $ ps | grep 62417
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > grier 62417 0.0 0.1 2473856 12320 ?? S 10:41AM 0:00.02 myprocess
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > This is similar to running a shell command with nohup:
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > $ nohup myprocess &
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > $ exit
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > Is there a way to make IDL spawn a child process that terminates when
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > the parent IDL session terminates?
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > All the best,
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> >
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> > David
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> You might try to keep your spawned process synchronized with the parent IDL session : maybe by using the UNIT keyword ?
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> Just a guess, I have no experience with unix.
>
>>
>
>>>
>
>>
>
>>>>
>
>>
>
>>>
>
>>
>
>>>> alx.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Thanks for thinking about this.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> Using the UNIT keyword is indeed useful for shutting down the child process from the parent IDL session. It doesn't help, however, if the user exits IDL without actively shutting down the
>
>>
>
>>>
>
>>
>
>>> child process.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
>
>>
>
>>>
>
>>
>
>>> the parent IDL session ends.
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> All the best,
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>>
>
>>
>
>>> David
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>> I'm looking for a way to spawn a child process that runs in the background and cleanly quits when
>
>>
>
>> Maybe by using some shared object ? A semaphore or a global memory region. But you would have to modify your child process accordingly.
>
>>
>
>> alx.
>
>
>
> This is a good suggestion. Unfortunately, I'm SPAWNing a precompiled executable: mencoder from the mplayer distribution.
>
>
>
> This issue comes up for me because IDL does not invoke the CleanUp method on objects when
>
> it exits. I _could_ write a replacement for EXIT that cleans up objects, but that still would leave open
>
> the possibility that the user could invoke the normal exit command and leave orphaned child
>
> processes running. Unfortunately, IDL does not have anything equivalent to the IDL_STARTUP
>
> mechanism for handling housekeeping during shutdown.
>
>
>
> I'm targeting unix-like systems, but would be interested in Windows solutions as well.
>
>
>
> All the best,
>
>
>
> David
> I'm targeting unix-like systems, but would be interested in Windows solutions as well.
With Windows, I would spawn (/NOWAIT) a powershell script which 1) launch the child process in background (Start-Job command), 2) test in loop that IDL is running (by name or pid), 3) kill the background process if IDL is no longer running.
alx.
|
|
|