comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » SPAWN background command without nohup?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
SPAWN background command without nohup? [message #88861] Sat, 28 June 2014 08:27 Go to next message
dg86 is currently offline  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 Go to previous messageGo to next message
lecacheux.alain is currently offline  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 Go to previous messageGo to next message
dg86 is currently offline  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 Go to previous messageGo to next message
lecacheux.alain is currently offline  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 Go to previous messageGo to next message
dg86 is currently offline  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 #88871 is a reply to message #88870] Mon, 30 June 2014 05:40 Go to previous messageGo to next message
Matthew Argall is currently offline  Matthew Argall
Messages: 286
Registered: October 2011
Senior Member
If you use SETENV to create an environment variable, it would at least give you access to the PIDs after IDL exits. If you could then monitor IDL to know when it exits, you could kill any remaining processes.
Re: SPAWN background command without nohup? [message #88875 is a reply to message #88870] Mon, 30 June 2014 09:21 Go to previous message
lecacheux.alain is currently offline  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.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Problem with SPAWN command in IDL code
Next Topic: Problem in performing band operation on image file

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 11:48:20 PDT 2025

Total time taken to generate the page: 0.00422 seconds