Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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?
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.
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
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.
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
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.
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.